@[email protected] to Programmer [email protected] • 8 days agoparseInt(5)lemmy.mlimagemessage-square63fedilinkarrow-up1474arrow-down16
arrow-up1468arrow-down1imageparseInt(5)lemmy.ml@[email protected] to Programmer [email protected] • 8 days agomessage-square63fedilink
minus-square@[email protected]linkfedilink92•8 days agoIt’s because parseInt is expecting a string, so the decimal gets converted to a string, and 0.0000005.toString() returns 5e-7.
minus-square@[email protected]linkfedilinkEnglish4•8 days agoMore like javascript L, even python would throw a TypeError for this example.
minus-square@[email protected]linkfedilink29•edit-28 days agoAnd to further expand on that, if you do pass in a sting string, it handles it correctly. > parseInt('0.0000005') 0
It’s because parseInt is expecting a string, so the decimal gets converted to a string, and
0.0000005.toString()
returns5e-7
.Common Dynamic Typing L
More like javascript L, even python would throw a TypeError for this example.
And to further expand on that, if you do pass in a
stingstring, it handles it correctly.> parseInt('0.0000005') 0
What if I pass in a Stewart Copeland?
😆 I’ll be watching you…
or a Honda civic