18

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 point numbers?

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

Output: 1700

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Masoud Darvishian
  • 3,754
  • 4
  • 33
  • 41
  • The answers you will get for the various languages will be similar, but not identical. Please choose **one** programming language and limit your question to it. – Robᵩ May 21 '12 at 14:19
  • 4
    E+3 == 10^3 == 10*10*10 == 1000. Thus, 1.7 * 1000 = 1700. It's called "engineering notation" afaik – Alex May 21 '12 at 14:20
  • I wonder why would anybody prefer 1.7E+3 compared to just 1700. – BlueM May 21 '12 at 14:24
  • @Rob: I don't know about asp, but for all the other languages he's chosen, the answer is in fact identical. – Benjamin Lindley May 21 '12 at 14:29
  • 7
    @BlueM - Because for much larger or smaller numbers it is more compact, e.g., 1.7E+30 is easier than typing or reading the 29 zeros in 1700000000000000000000000000000. (And if you know you'll be dealing with a range of large numbers it is often easier to stick to the one notation style. I wouldn't use E notation if I knew all the numbers I needed were only up to four or five digits.) – nnnnnn May 22 '12 at 06:04

4 Answers4

23

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
Dmitry Osinovskiy
  • 9,999
  • 1
  • 47
  • 38
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
17

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

1.7E+3 = 1.7 x 103 = 1700

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
James Michael Hare
  • 37,767
  • 9
  • 73
  • 83
6

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

1.7 -> 17.0 -> 170.0 -> 1700.0

Charleh
  • 13,749
  • 3
  • 37
  • 57
3

E+3 = 103, so 1.7 · 103 = 1700

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Boundless
  • 2,444
  • 2
  • 25
  • 40