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)

11 Tips That Make You a Better Typescript Programmer

typescript

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay