Reputation: 19903
I have this value : 12345678,99
I'd like have this : €12.345.678 to resume "." as thousand separator, not show decimal number and add the € befor the number.
Do you know the formatting string ?
Thanks,
Upvotes: 1
Views: 295
Reputation: 35716
You need to use a culture with the right seperator and a bit of custom formatting to round the decimal values and prepend the currency symbol.
somthing like,
var value = 12345678.99m;
return value.ToString("€00,##0", CultureInfo.CreateSpecificCulture("el-GR"));
If your culture have the right currency symbol I think this is better,
return value.ToString("C0", CultureInfo.CreateSpecificCulture("el-GR"));
Upvotes: 0
Reputation: 149
Try this:
double jjj = 12345678.99d;
NumberFormatInfo nfi = new CultureInfo("en-GB", false).NumberFormat;
nfi.CurrencyGroupSeparator = ".";
MessageBox.Show(jjj.ToString("C0", nfi));
Upvotes: 0
Reputation: 64487
You can build your own formatter if the style you want isn't specific to a culture (note the console shows a ? for the € symbol on the default font, that doesn't mean it hasn't worked):
private static void Main(string[] args)
{
NumberFormatInfo nfi = new NumberFormatInfo();
nfi.CurrencySymbol = "€";
nfi.CurrencyGroupSeparator = ".";
nfi.CurrencyDecimalSeparator = ".";
decimal val = 300099.99M;
Console.WriteLine(val.ToString("c", nfi));
Console.Read();
}
If it is specific to a culture, then you can do the following (adapted from MSDN with npinti's suggested culture of it-IT):
public static void Main()
{
int i = 100;
CultureInfo it = new CultureInfo("it-IT");
Console.WriteLine(i.ToString("c", it));
Console.Read();
}
Upvotes: 0
Reputation: 5042
Lots of examples: http://www.csharp-examples.net/string-format-double/
http://blog.stevex.net/string-formatting-in-csharp/
Upvotes: 0