DEV Community

Kueiapp
Kueiapp

Posted on

Why can e be used in the tab of input type=number?

Origin:http://blog.kueiapp.com/programming-tw/為何-e-可以輸入-input-typenumber-的標籤中/

When learning HTML, I believe you will have a confusion. Obviously, the type is specified as a number in the input tag, but why the “character ‘e’” can still be input? How strange!

<input type="number" value="123" />
Enter fullscreen mode Exit fullscreen mode

Image description

Meaning of e

Multiply by 10 to the Nth power

The main reason for this is that JavaScript has extended the use of the scientific notation “e” to represent the number of zeros.

For example, the result of 2 x 100000 can be written as “2e+08”. For example, the result of 2 x 100000 can be written as “2e+08”, which is shortened to “2e5” or “2E5” (case insensitive) in JavaScript;

On the other hand, because JavaScript itself uses float to do calculations, there are often a lot of bits, and using e can shorten the representation of the number.

Examples

  1. 2 x 100000 → 2E+05 → 2e5

  2. 7.8 x 10⁷ → 7.8E+07 → 7.8e7

  3. 1.03 x 10⁸ → 1.03E+08 → 1.03e8

Origin:http://blog.kueiapp.com/programming-tw/為何-e-可以輸入-input-typenumber-的標籤中/

Top comments (0)