Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use scientific notation in js?

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?

like image 731
user983302 Avatar asked Nov 26 '14 14:11

user983302


People also ask

How to write scientific notation literal in JavaScript?

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.

Is there a way to read Numbers in scientific notation?

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.

How do you write 10-12 in scientific notation?

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.

Is there a way to roll scientific notation?

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.


1 Answers

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.

like image 91
meagar Avatar answered Oct 02 '22 13:10

meagar