views:

57

answers:

2

I would like my WPF application to display all percentages without % sign. For example 20% would be displayed as "20" but i still want to use the standard formatting for percentages (so i get the benefit of string formatter to multiply it by 100 for me)

in other words, how do i get string.Format("0.00%", 0.2) to output "20" but not "20%"?

Is it possible to globally define PercentSymbol as empty string for the entire application?

In particular i am using ContentStringFormat in my WPF application to format the numbers and percentages. Maybe i can do it directly in WPF.

A: 

Provide your own NumberFormatInfo to String.Format. Example based on the invariant culture:

NumberFormatInfo info = (NumberFormatInfo) CultureInfo.CurrentCulture.NumberFormat.Clone();
info.PercentSymbol = String.Empty;
string s = String.Format(info, "{0:00%}", 0.02);
Julien Lebosquain
Can i still use ContentStringFormat with a custom NumberFormatInfo?
Vitalik
Unfortunately, I don't think so.
Julien Lebosquain
A: 

In theory the way you would do this is to create your own custom CultureInfo for your application. Then you would create your own NumberFormatInfo. In this you can define the PercentSymbol.

Keltex
How do set custom CultureInfo on wpf application?
Vitalik