TheBoubou
TheBoubou

Reputation: 19903

formatting currency

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

Answers (5)

Jodrell
Jodrell

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

Tim Chan Yiu Man
Tim Chan Yiu Man

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

Adam Houldsworth
Adam Houldsworth

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

npinti
npinti

Reputation: 52185

This MSDN tutorial might be of help. This list provides a list of cultures you can use. Since you want to use the . as a thousand seperator and use the Euro currency, you should be fine using the Italian locale, it-IT.

Upvotes: 1

Related Questions