var time_arr = process.hrtime(start);
var time = (time_arr[0] * 1e9 + time_arr[1]) / 1e6;

What does it mean when the calculation has to multiply by 1e9 and divide by 1e6 ?

3

1 Answer

What does it mean when the calculation has to multiply by 1e9 and divide by 1e6 ?

It means that it's multiplied by 1 billion and divided by 1 million.

  • 1e9 means 1 * 10 to the 9th power, which is 1 billion (1000000000).
  • 1e6 means 1 * 10 to the 6th power, which is 1 million (1000000).

You can think of it as 1 and 9 zeroes, 1 and 6 zeroes etc.

It doesn't have to be 1, it can be:

  • 3e4 meaning 30000

or:

  • 1.2e6 meaning 1200000

You can also use negative powers of ten for decimal fractions:

  • 1e-1 is 0.1
  • 1e-2 is 0.01
  • etc.

It's useful for very large or very small numbers where you don't want to count zeroes.

See the scientific notation on Wikipedia: