2

We're having a discussion in the office about how the hell this math works in JavaScript.

There was an instance where we were multiplying by 010 instead of 10 and this gave the incorrect returned value.

For example...

25.25 * 010 = 202

25.25 * 10 = 252.5 as expected

whats even weirder is if you do parseFloat(010) it gives you 8!

LF00
  • 27,015
  • 29
  • 156
  • 295
Adam91Holt
  • 1,018
  • 1
  • 14
  • 28

2 Answers2

5

For 010 is decimal 8, so it get 202.

console.log(25.25 * 010);
LF00
  • 27,015
  • 29
  • 156
  • 295
0

Look at this answer for Java: Why "010" equals 8?. JavaScript has to do the same.

The answer is, that an octal number starts with a leading zero 0.

Community
  • 1
  • 1
Guybrush
  • 710
  • 7
  • 12