如果我想显示 4 个小数点,那么正确的格式是什么?
问问题
4172 次
3 回答
7
String.Format("{0:0.0000}", floatNum);
不管值是什么,它总是显示四位小数。其他选项可以在这里找到:http ://www.csharp-examples.net/string-format-double/
于 2010-02-12T19:07:09.563 回答
0
就个人而言,我更喜欢这种方法。
floatNum.ToString("N4")
于 2010-02-12T22:00:11.550 回答
-1
请注意,它会四舍五入:
decimal d = 1.23456789M;
Console.WriteLine(d.ToString("0.0000"));
// Output: 1.2345
作为格式字符串,它将是:
Console.WriteLine("{0:0.0000}", d);
于 2010-02-12T19:07:10.623 回答