C# 浮点数中的 E 是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10687016/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 14:49:53  来源:igfitidea点击:

What is E in floating point?

c#.net

提问by Masoud Darvishian

What is E+3? What exactly happens here? Can we use this approach in other data types or can we only use it in floating points?

什么是E+3?这里究竟发生了什么?我们可以在其他数据类型中使用这种方法还是只能在浮点数中使用它?

static void Main(string[] args)
{
    double w = 1.7E+3;
    Console.WriteLine(w);
}

Output: 1700

输出:1700

采纳答案by CodeCaster

E notation

Most calculators and many computer programs present very large and very small results in scientific notation. Because superscripted exponents like 107cannot 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 "x 10b") and is followed by the value of the exponent. Note that in this usage the character e is not related to the mathematical constant eor 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). The use of this notation is not encouraged by publications.

E 符号

大多数计算器和许多计算机程序以科学记数法显示非常大和非常小的结果。因为像 10 7这样的上标指数不能总是方便地显示,所以字母 E 或 e 通常用于表示 10 次幂(将写成“x 10 b”),然后是指数的值. 请注意,在这种用法中,字符 e 与数学常数e或指数函数e x无关(与大写 E 不太可能混淆);尽管它代表指数,但该符号通常被称为(科学)E 符号或(科学)e 符号,而不是(科学)指数符号(尽管后者也会出现)。出版物不鼓励使用此符号。



As for your second question:

至于你的第二个问题:

can we use this approach in other data type or we can only use it in floating points?

我们可以在其他数据类型中使用这种方法还是只能在浮点数中使用它?

See the C# spec:

请参阅C# 规范

Real literals [the type of numeric literals that are allowed an Ein them] are used to write values of types float, double, and decimal.

实际文字[被允许的数字文字的类型E在其中]用于的类型的写入值floatdoubledecimal

However, you have to cast or suffix the literal appropriately when assigning to anyhting other than a Double, because any literal with an eor Ein it is recognized as a Doublein Visual Studio. I cannot find where this behavior is specified.

但是,在分配给 a 以外的Double任何内容时,您必须适当地转换或添加文字后缀,因为在 Visual Studio 中,任何带有e或 的文字E都被识别为 a Double。我找不到指定此行为的位置。

float f1 = 7E1;     // Compile error. Needs F suffix (7E1F)
decimal d1 = 8E2;   // Compile error. Needs M suffix (8E2M)
double d2 = 9E3;    // Works.

int overninethousand = (int)9E3 + 1; // Works

回答by James Michael Hare

In general, that's exponential/scientific notation...

一般来说,这是指数/科学记数法......

1.7E+3 = 1.7 x 10^3 = 1700

1.7E+3 = 1.7 x 10^3 = 1700

回答by Charleh

E+3 means the decimal place is moved 3 times to the right

E+3 表示小数点向右移动 3 次

1.7 -> 17.0 -> 170.0 -> 1700.0

1.7 -> 17.0 -> 170.0 -> 1700.0

回答by Boundless

E+3 = 10^3, so 1.7 * 10^3 = 1700