c# decimal.toString()
conversion problem
Example: I have a value in decimal(.1) when I convert decimal to string using toString() it return
For this to be happening, the thread's current culture must be one that uses a separator of comma instead of dot.
You can change this on a per ToString
basis using the overload for ToString
that takes a culture:
var withDot = myVal.ToString(CultureInfo.InvariantCulture);
Alternatively, you can change this for the whole thread by setting the thread's culture before performing any calls to ToString()
:
var ci = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
var first = myVal.ToString();
var second = anotherVal.ToString();