I want to convert "-1.775" to German "-1,775". How to do it using C# ?
I tried
string abc = "-1.775";
Convert.ToDouble(abc).ToString("F3");
This results me "-1775,000
"
I am Running my application on a German OS.
CodePudding user response:
Try
string.Format(System.Globalization.CultureInfo.GetCultureInfo("de-DE"), "{0:0.0}", -1.775);
CodePudding user response:
Assuming the value is originally some kind of numeric type, for example:
double nDouble = -1.775;
decimal nDecimal = -1.775m;
float nFloat = -1.775f;
...you can use the ToString(IFormatProvider)
method of the type with a specified culture. For example:
string strDouble = nDouble.ToString(new CultureInfo("de"));
string strDecimal = nDecimal.ToString(new CultureInfo("de"));
string strFloat = nFloat.ToString(new CultureInfo("de"));