@[email protected] to Programmer [email protected] • 2 months agoparseInt(5)lemmy.mlimagemessage-square63fedilinkarrow-up1478arrow-down16
arrow-up1472arrow-down1imageparseInt(5)lemmy.ml@[email protected] to Programmer [email protected] • 2 months agomessage-square63fedilink
minus-square@[email protected]linkfedilink94•2 months 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•2 months agoMore like javascript L, even python would throw a TypeError for this example.
minus-square@[email protected]linkfedilink29•edit-22 months 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