I need to convert double to string with two decimal digits separated with 'dot' My concern is that dot must be always used as separator.
We can use StringBuilder and StringBuffer append function to convert double to string.
To convert a Decimal value to its string representation using a specified culture and a specific format string, call the Decimal. ToString(String, IFormatProvider) method.
The toString() method of the class Double To convert Double value to String. Read the required primitive double value in to the Double class reference variable (autoboxing happens). Convert it into a String using the toString() method.
The simplest way is to specify CultureInfo.InvariantCulture
as the culture, e.g.
string text = d.ToString("N2", CultureInfo.InvariantCulture);
Perhaps to avoid messing up with CultureInfo settings on clients systems, we better set a concrete way to force the machine to use dot as decimal separator and not thousand separator ==> regardless of culture! So,
NumberFormatInfo fi= new NumberFormatInfo();
fi.NumberDecimalSeparator = ".";
string doubleDotDecimalNr = doubleNr.ToString(fi);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With