var a = 5.0;
var b = a * 10e-12;
b *= 10e+12
print(b)
Why b equals 500 instead of 5?
As far as I know 10^(-12) equals to 1/(10^12), how can i rewrite the code?
How to write Scientific notation literal in Javascript 1 Description. Floating-point values can be represented using e-notation. ... 2 Example. In this example, floatNum is equal to 31,250,000. ... 3 Note. E-notation can also be used to represent very small numbers, such as 0.00000000000000003 , which can be written more succinctly as 3e-17.
There is still a use for this when you are dealing with numbers up to a certain size. Scientific notation will be hard to read for users who don't know scientific notation too after all. There's Number.toFixed, but it uses scientific notation if the number is >= 1e21 and has a maximum precision of 20.
But what you wrote wasn't 10 -12, nor did you write 10 12. What you wrote was 10 × 10 12 and 10 × 10 -12: Proper scientific notation is 1e-12 and 1e12. The e stands for "ten to the power of", so you don't need to multiply that value by ten again.
Scientific notation will be hard to read for users who don't know scientific notation too after all. There's Number.toFixed, but it uses scientific notation if the number is >= 1e21 and has a maximum precision of 20. Other than that, you can roll your own, but it will be messy.
Because math. 10e1
is 100
and 10e-1
is 1
.
10e1 * 10e-1
is 100
. 10e2 * 10e-2
is 100
.10e3 * 10e-3
is 100
.You can very easily extend this to figure out that 10eN * 10e-N
is always going to be 100
.
If you want actual scientific notation, as in 1 * 10 ^ 2
, you want 1e12
and 1e-12
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With