Search code examples
c#.netglobalization

Currency format


i have a issue with some string formats, i'm forcing the culture when formatting specific formats:

get { return String.Format("{0:###,###,###,###,##0}", Convert.ToDecimal(_monthPay, new System.Globalization.CultureInfo("es-ES"))); }

so that i can get this:

$300.000,01

On localhost it works fine, but when i publish to the server, i get this:

$300,000.01

I don't know why!!! I don't have access to the server, so I can't change the regional settings on the server; is there another way to solve it? so that i works properly on localhost and when publishing?

Thanks.


Solution

  • What you're doing here is telling the Convert.ToDecimal function what _monthPay will look like. What you're expecting is that the String will be formatted with the culture info.

    You should be telling String.Format what culture to use:

    String.Format( new System.Globalization.CultureInfo("es-ES"), "{0:###,###,###,###,##0.##}", Convert.ToDecimal(_monthPay)));