Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

c# - What is E in floating point?

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?

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

Output: 1700

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

E notation

Most calculators and many computer programs present very large and very small results in scientific notation. 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 "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 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). The use of this notation is not encouraged by publications.


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:

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

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...