views:

350

answers:

1

I have a little problem formatting double values in my XAML code.

double price = 10300.455;

This number should be displayed as 10,300.45 on US systems and as 10.300,45 on german systems.

So far I managed to limit the numbers with the following

Binding="{Binding price, StringFormat=F2}"

But the result is 10300.45 and that is not what I had in mind. I could fix this easily using a converter but I don't want to do that if there is another way around. Just the right Formatter would be fine.

+4  A: 
Binding="{Binding price, StringFormat=N2}" 

Try N instead of F, N is number format, which based on different culture automatically displays number formating, look at sample code below which is console app, however if binding uses correct culture, you will get correct value. F2 is fixed point notation.

    double price = 10300.455;

    Console.WriteLine(price.ToString("N2", 
        CultureInfo.CreateSpecificCulture("de-DE") ));
    // displays 10.300,46

    Console.WriteLine(price.ToString("N2",
        CultureInfo.CreateSpecificCulture("en-US") ));
    // displays 10,300.46
Akash Kava