为什么我的浮点值在转换为字符串时有一个“E”字符?
Why does my floating point value have an `E` character when I convert it to a string?
txtDebugLog.Invoke(new MethodInvoker(delegate()
{
fps.Frame();
ggg = fps.GetFPS();
txtDebugLog.Text = String.Format("{0}\r\n{1}", ggg, txtDebugLog.Text);
})
txtDebugLog
是一个文本框。
在本例中使用我在 ggg
上看到的断点,其值为:
0.00000102593151
然后我点击继续并在 TextBox
中看到:
1.025932E-06
来自the sub-section "E notation" of the Wikipedia article on "scientific notation":
Most calculators and many computer programs present very large and very small results in scientific notation, typically invoked by a key labelled EXP (for exponent), EEX (for enter exponent), EE, EX, or E depending on vendor and model. Because superscripted exponents like 107 cannot always be conveniently displayed, the letter E or e is often used to represent times ten raised to the power of (which would be written as "× 10b") and is followed by the value of the exponent; in other words, for any two real numbers a and b, the usage of "aEb" would indicate a value of a × 10b. Note that in this usage the character e is not related to the mathematical constant e or the exponential function ex (a confusion that is less likely with capital E); and though it stands for exponent, the notation is usually referred to as (scientific) E notation or (scientific) e notation, rather than (scientific) exponential notation (though the latter also occurs).
您的浮点值 ggg
的值非常小。当您将其转换为字符串时,如此调用中所发生的那样
String.Format("{0}\r\n{1}", ggg, txtDebugLog.Text);
它将被转换为使用 指数 格式表示该值的字符串。您可以阅读什么是指数格式,也称为科学记数法,here.
如果你想使用不同的格式,你必须自己指定。许多标准格式可用,您可以在进行转换时明确指定。使用特定格式将 double
转换为 string
可以通过调用 double.ToString(format)
方法来完成。
那里列出了几种可用的标准格式,包括您将从中获得的输出。
如果不指定,则使用的默认格式是 General Format Specifier ("G"),即:
Converts a number to the most compact of either fixed-point or
scientific notation, depending on the type of the number and whether a
precision specifier is present. The precision specifier defines the
maximum number of significant digits that can appear in the result
string.
txtDebugLog.Invoke(new MethodInvoker(delegate()
{
fps.Frame();
ggg = fps.GetFPS();
txtDebugLog.Text = String.Format("{0}\r\n{1}", ggg, txtDebugLog.Text);
})
txtDebugLog
是一个文本框。
在本例中使用我在 ggg
上看到的断点,其值为:
0.00000102593151
然后我点击继续并在 TextBox
中看到:
1.025932E-06
来自the sub-section "E notation" of the Wikipedia article on "scientific notation":
Most calculators and many computer programs present very large and very small results in scientific notation, typically invoked by a key labelled EXP (for exponent), EEX (for enter exponent), EE, EX, or E depending on vendor and model. Because superscripted exponents like 107 cannot always be conveniently displayed, the letter E or e is often used to represent times ten raised to the power of (which would be written as "× 10b") and is followed by the value of the exponent; in other words, for any two real numbers a and b, the usage of "aEb" would indicate a value of a × 10b. Note that in this usage the character e is not related to the mathematical constant e or the exponential function ex (a confusion that is less likely with capital E); and though it stands for exponent, the notation is usually referred to as (scientific) E notation or (scientific) e notation, rather than (scientific) exponential notation (though the latter also occurs).
您的浮点值 ggg
的值非常小。当您将其转换为字符串时,如此调用中所发生的那样
String.Format("{0}\r\n{1}", ggg, txtDebugLog.Text);
它将被转换为使用 指数 格式表示该值的字符串。您可以阅读什么是指数格式,也称为科学记数法,here.
如果你想使用不同的格式,你必须自己指定。许多标准格式可用,您可以在进行转换时明确指定。使用特定格式将 double
转换为 string
可以通过调用 double.ToString(format)
方法来完成。
那里列出了几种可用的标准格式,包括您将从中获得的输出。
如果不指定,则使用的默认格式是 General Format Specifier ("G"),即:
Converts a number to the most compact of either fixed-point or scientific notation, depending on the type of the number and whether a precision specifier is present. The precision specifier defines the maximum number of significant digits that can appear in the result string.