gpt4 book ai didi

c# - Double.ToString() 何时以科学计数法返回值?

转载 作者:太空狗 更新时间:2023-10-29 18:16:31 24 4
gpt4 key购买 nike

我假设它与前导零或尾随零的数量有关,但我在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com