如何改变符号小数点double.ToString()? [英] How to change symbol for decimal point in double.ToString()?
本文介绍了如何改变符号小数点double.ToString()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想小数点更改为C#另一个角色。我有一个双
变量值
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?
推荐答案
创建一个扩展方法?
Console.WriteLine(value.ToGBString());
// ...
public static class DoubleExtensions
{
public static string ToGBString(this double value)
{
return value.ToString(CultureInfo.GetCultureInfo("en-GB"));
}
}
这篇关于如何改变符号小数点double.ToString()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文