+ 2
What's 111,111,111^2?
My calculator says 12,345,678,987,654,321 (ending with 1), but JavaScript says 12,345,678,987,654,320 (ending with 0). Can anyone explain this?
2 Answers
+ 5
If the last digit of n is 1, n to the power of x, where x >= 0, will always end with the digit 1, so your calculator is correct.
And Prometheus đ¸đŹ [Daily Target: 1.5k] is right - There is a maximum value to which JS can safely operate on. Exceeding that limit will result in inaccurate conversions/calculations.
https://stackoverflow.com/questions/33669588/wrong-value-when-parsing-a-number-of-type-string-to-number
+ 4
That is probably because JavaScript might not be able to handle with too many digits when dealing with such operations.