什么时候Double.ToString()返回科学记数法的值? [英] When does Double.ToString() return a value in scientific notation?

查看:182
本文介绍了什么时候Double.ToString()返回科学记数法的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为它会是与领先或尾随零的数目,但我不能找到MSDN什么,给我一个具体的答案。

I assume that it has something to do with the number of leading or trailing zeroes, but I can't find anything in msdn that gives me a concrete answer.

在什么时候 Double.ToString(CultureInfo.InvariantCulture)开始在科学记数法返回值?

At what point does Double.ToString(CultureInfo.InvariantCulture) start to return values in scientific notation?

推荐答案

从文档的 Double.ToString(的IFormatProvider)

本实例格式化通用数值格式说明(G)。

This instance is formatted with the general numeric format specifier ("G").

从文档的的常规数字格式说明

固定点符号用于如果这将导致从表达在科学记数的指数是低于-5和小于精度说明更大;否则,使用科学记数法。结果中包含如果需要,和小数点后尾随零省略小数点。如果精度说明是本和显著位在结果数超过指定的精度,多余的尾随位被四舍五入除去。

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.

默认精度说明符双击被记录为15

The default precision specifier for Double is documented to be 15.

虽然前面的表,它的措辞略有不同:

Although earlier in the table, it's worded slightly differently:

结果:最紧凑无论是定点或科学计数法

Result: The most compact of either fixed-point or scientific notation.

我还没有制定出这两个是否总是等同于一个双击值...

I haven't worked out whether those two are always equivalent for a Double value...

编辑:按照亚伯的评论:

As per Abel's comment:

此外,它并不总是最简单的符号。 0.0001越大则1E-04,但第一个被输出。在MS文档不会在这里完成。

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以上。)

That fits in with the more detailed description, of course. (As the exponent required is greater than -5 and less than 15.)

这篇关于什么时候Double.ToString()返回科学记数法的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆