【发布时间】:2019-12-02 17:11:14
【问题描述】:
查看the documentation on Standard Numeric Format Strings。它说
但是,如果数字是 Decimal 并且省略了精度说明符,则始终使用定点表示法并保留尾随零。
对我来说,尾随零的定义只是指数字末尾的任何零,无论它们是在小数点之前还是之后。
因此,根据我对尾随零的理解,300 和 3.00 都有两个尾随零。
但是,当我实际尝试时,似乎只保留了小数点前的尾随零。
我只是误解了此处尾随零的定义,还是会保留小数点后的零?
using System;
public class Program
{
public static void Main()
{
Console.WriteLine(new Decimal(10.000).ToString("G"));
Console.WriteLine(new Decimal(0.000000).ToString("G"));
Console.WriteLine(new Decimal(30000).ToString("G"));
}
}
【问题讨论】:
标签: c# .net number-formatting