Math.Round((ClosePrice - OpenPrice), 5) = -0.00001
,但是当我把它转换成的toString它给 “-1E-05”十进制字符串转换问题
Math.Round((ClosePrice - OpenPrice), 5).ToString() = "-1E-05"
为什么会是这样?我怎样才能获得“-0.00001”
Math.Round((ClosePrice - OpenPrice), 5) = -0.00001
,但是当我把它转换成的toString它给 “-1E-05”十进制字符串转换问题
Math.Round((ClosePrice - OpenPrice), 5).ToString() = "-1E-05"
为什么会是这样?我怎样才能获得“-0.00001”
您可以使用格式说明上MSDN's Standard Numeric Format Strings
double foo = -0.00001;
Console.WriteLine(foo.ToString("f5"));
ToString()
为证明选择基于价值被格式化来实现的最紧凑表示的格式。如果你想选择一个特定的格式,你需要使用ToString(string format)
超载来代替。例如,如果你调用
Math.Round((ClosePrice - OpenPrice), 5).ToString("N5")
你会得到"-0.00001"
字符串作为结果。
每个类从object
(并因此任何类)继承具有.ToString()
方法。它所输出取决于天气它被覆盖,如果是,它如何被覆盖(即什么也实施者想给出的字符串,其同样的过程,如果实施.ToString()
方法之一,你将通过您的
这是关于“为什么” - “如何”已被其他人回答的问题