What's 111,111,111^2? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

23rd Aug 2019, 1:25 PM
C. Scheler
C. Scheler - avatar
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
23rd Aug 2019, 1:35 PM
Fermi
Fermi - avatar
+ 4
That is probably because JavaScript might not be able to handle with too many digits when dealing with such operations.
23rd Aug 2019, 1:26 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar