- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我假设它与前导零或尾随零的数量有关,但我在 msdn 中找不到任何能给我具体答案的内容。
Double.ToString(CultureInfo.InvariantCulture)
什么时候开始以科学计数法返回值?
最佳答案
来自 Double.ToString(IFormatProvider)
的文档:
This instance is formatted with the general numeric format specifier ("G").
来自 General Numeric Format Specifier 的文档:
Fixed-point notation is used if the exponent that would result from expressing the number in scientific notation is greater than -5 and less than the precision specifier; otherwise, scientific notation is used. The result contains a decimal point if required, and trailing zeros after the decimal point are omitted. If the precision specifier is present and the number of significant digits in the result exceeds the specified precision, the excess trailing digits are removed by rounding.
However, if the number is a Decimal and the precision specifier is omitted, fixed-point notation is always used and trailing zeros are preserved.
Double
的默认精度说明符记录为 15。
虽然在表的前面,它的措辞略有不同:
Result: The most compact of either fixed-point or scientific notation.
我还没有弄清楚这两个值是否总是等同于 Double
值...
编辑:根据 Abel 的评论:
Also, it is not always the most compact notation. 0.0001 is larger then 1E-04, but the first is output. The MS docs are not complete here.
当然,这符合更详细的描述。 (因为要求的指数大于-5小于15。)
关于c# - Double.ToString() 何时以科学计数法返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12977746/
我是一名优秀的程序员,十分优秀!