-1

I need to change the format of variable, depending on CurrentCulture

Variable is a Decimal

This is my current change statement :

 string auxst = String.Format(CultureInfo.CurrentCulture, "#,##0.00", variable);

I need to know what to put in the second parameter so that this happens:

Variable = 150.465,1242345

If CurrentCulture is "es ES"(spain) ->  auxst = "150.465,1242345"

If CUrrentCulture is "en EN" ->  auxst = "150,465.1242345"

Thx for the help

DLeh
  • 23,806
  • 16
  • 84
  • 128

1 Answers1

0

If you use CurrentCulture, do not specify it.

You should use Decimal.ToString():

Decimal variable = 15465.1242345M;
string auxst = variable.ToString("N");
  • Please *do* specify it. See http://stackoverflow.com/questions/475383/is-cultureinfo-currentculture-really-necessary-in-string-format – nvoigt Oct 20 '15 at 15:51
  • You _can_ for documentation purposes only, as the link you provide says. – Ludovic Dubois Oct 20 '15 at 16:09
  • Not specifying it is meant to document that you haven't thought about it. Specifying it *documents* you *have* thought about it. So as you have thought about it and using CurrentCulture is a choice, not an oversight, you should document it. – nvoigt Oct 20 '15 at 16:14
  • Not specifying it doesn't mean you haven't thought about it. It just means you don't know if the developer has thought about it or not. This discussion is just politic. :-) But we do not care as it doesn't change much the answer for PruebasDev. The point is use "N" formatter. :-) – Ludovic Dubois Oct 20 '15 at 16:18
  • Indeed. So your advice should not be "do not specify", because you *have* thought about it and therefor *should* document that you did. – nvoigt Oct 20 '15 at 16:20