开发者

Need to convert double or decimal to string

开发者 https://www.devze.com 2023-01-21 13:44 出处:网络
I need to convert double to string with two decimal digit开发者_如何学Gos separated with \'dot\'

I need to convert double to string with two decimal digit开发者_如何学Gos separated with 'dot' My concern is that dot must be always used as separator.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消