Reputation: 19903
In the example below, comma is the decimal separator.
I have this : 125456,89
I'd like have this : 125.456,89; other exemple : 23456789,89 => 23.456.789,89
Thanks,
Upvotes: 0
Views: 438
Reputation: 1499800
Usually to format a number as a currency, you should use the "c" format specifier:
string formatted = price.ToString("c");
That will use the current thread's default culture to determine the formatting rules, but you can specify it explicitly if you want.
If that doesn't help, please give us more information and read these two pages:
EDIT: From your comment, it sounds like you either want to specify an explicit custom numeric format string, or build your own NumberFormatInfo
object (which is just a matter of setting properties after cloning an existing one) and pass that into a formatting call.
Upvotes: 1
Reputation: 174289
You can use this:
125456.89.ToString("#,###.00")
It will automatically use the correct decimal point and group separator for the current culture. It differs from the other solutions so far in that it doesn't automatically append the currency symbol.
Upvotes: 1
Reputation: 4114
look at this examples
double value = 12345.6789;
Console.WriteLine(value.ToString("C", CultureInfo.CurrentCulture));
Console.WriteLine(value.ToString("C3", CultureInfo.CurrentCulture));
Console.WriteLine(value.ToString("C3",
CultureInfo.CreateSpecificCulture("da-DK")));
// The example displays the following output on a system whose
// current culture is English (United States):
// $12,345.68
// $12,345.679
// kr 12.345,679
Upvotes: 2
Reputation: 6891
quoted from another post
Create a custom NumberFormatInfo instance and pass that in when calling ToString().
NumberFormatInfo nfi = new NumberFormatInfo();
nfi.NumberGroupSeparator = ".";
nfi.NumberDecimalSeparator = ",";
double s = 219171;
string result = s.ToString("N2", nfi);
NumberFormatInfo belongs to System.Globalization
Upvotes: 0