Wednesday, November 22, 2017

C# : How Convert doubles to strings ALWAYS with dots instead of commas

To convert a double to string ALWAYS with dots instead of commas (as it is used in some languages like Italian or German) you need to use an overloaded version of the ToString() method.



Example:

double dVal = 77.55;
string sVal = dVal.ToString(System.Globalization.CultureInfo.InvariantCulture);
// sVal will be  always "77.55"


or if you use System.Globalization


using System.Globalization;

double dVal = 77.55;
string sVal = dVal.ToString(CultureInfo.InvariantCulture);

No comments:

Post a Comment

Your comment will be visible after approval.