如何在double.ToString()中更改小数点的符号? [英] How to change symbol for decimal point in double.ToString()?
问题描述
double
变量值
double value;
当我使用命令:
Console.WriteLine(value.ToString()); //输出是1,25
我知道我可以这样做:
Console.WriteLine(value.ToString(
CultureInfo.CreateSpecificCulture(en-GB))); //输出是1.25
但我不喜欢它,因为它很长,我需要在我的程序中经常出现。
是否有更短的版本设置小数点真的是点,而不是逗号,在我的文化中是平常的?
一些快捷方式是创建一个NumberFormatInfo类,将其NumberDecimalSeparator属性设置为。并且只要你需要,就使用Class作为ToString()方法的参数。
NumberFormatInfo nfi = new NumberFormatInfo();
nfi.NumberDecimalSeparator =。;
value.ToString(nfi);
I would like to change decimal point to another character in C#. I have a double
variable value
double value;
and when I use the command:
Console.WriteLine(value.ToString()); // output is 1,25
I know I can do this:
Console.WriteLine(value.ToString(
CultureInfo.CreateSpecificCulture("en-GB"))); // output is 1.25
but I don't like it very much because it's very long and I need it quite often in my program.
Is there a shorter version for setting "decimal point" really as point and not comma as is in my culture is usual?
Some shortcut is to create a NumberFormatInfo class, set its NumberDecimalSeparator property to "." and use the class as parameter to ToString() method whenever u need it.
NumberFormatInfo nfi = new NumberFormatInfo();
nfi.NumberDecimalSeparator = ".";
value.ToString(nfi);
这篇关于如何在double.ToString()中更改小数点的符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!