Assuming an invariant culture, is it possible to define a different group separator in the format - than the comma?
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Console.WriteLine(String.Format("{0:#,##0}", 2295));
Output:
2,295
Desired output:
2.295
The invariant culture is a requirement because currencies from many different locales are being formatted with format strings, that have been user defined. Ie for Denmark they have defined the price format to be "{0:0},-", while for Ireland it might be "€{0:#,##0}".
Now let's get started. In most European countries, a comma is used to separate the integral part of a number from the decimal part. This means, for example, that three hundred euros and ten cents is written as 300,10—with a comma as a decimal marker.
The three most spoken international auxiliary languages, Ido, Esperanto, and Interlingua, all use the comma as the decimal separator. Interlingua has used the comma as its decimal separator since the publication of the Interlingua Grammar in 1951.
The decimal separator is also called the radix character. Likewise, while the U.K. and U.S. use a comma to separate groups of thousands, many other countries use a period instead, and some countries separate thousands groups with a thin space.
When you have different format strings, this does not mean that you have to use InvariantCulture. If you have a format string for germany e.g. you format this string using the Culture("de-de"):
String.Format(CultureInfo.GetCultureInfo( "de-de" ), "{0:0},-", 2295) //will result in 2.295,-
String.Format(CultureInfo.GetCultureInfo( "en-us" ), "{0:0},-", 2295) //will result in 2,295,-
Alternatively you can specify your custom number format info:
NumberFormatInfo nfi = new NumberFormatInfo( )
{
CurrencyGroupSeparator = ":"
};
String.Format(nfi, "{0:0},-", 2295) //will result in 2:295,-
The normal approach would be to not use an Invariant culture.
You do specify the formatting in Invariant style, but the proper symbols would be substituted, #,##0.00
will come out as 1.234,50 or as 1,235.50 depending on the actual culture used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With