在C#双格式
问题描述:
我有双重价值。我想格式化x.yz.格式这个值我该怎么做呢?我不断收到数字截断。谁能告诉我该怎么做这在C#?
I have a double value. I want to format this value in the format of x.yz. How do I do this? I keep getting digits truncated. Can someone tell me how to do this in C#?
谢谢!
答
使用格式字符串中解释:
Using format strings is explained in:
- Standard Numeric Format Strings
- Custom Numeric Format Strings
例如,尝试:
-
(0.56789)的ToString(F2)
-
(0.56789)的ToString(0.00)
。
(0.56789).ToString("F2")
-
(0.56789).ToString("0.00")
.
请注意所产生的价值不会被截断,但四舍五入在两种情况下,导致0.57
。
Note that the resulting value is NOT truncated, but rounded in both cases, resulting in "0.57"
.