@OsrsNeedsF2P@lemmy.ml to Programmer Humor@programming.dev • 5 days agoparseInt(5)lemmy.mlimagemessage-square61fedilinkarrow-up11arrow-down10
arrow-up11arrow-down1imageparseInt(5)lemmy.ml@OsrsNeedsF2P@lemmy.ml to Programmer Humor@programming.dev • 5 days agomessage-square61fedilink
minus-square@danda@lemmy.ziplinkfedilink0•5 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@spizzat2@lemm.eelinkfedilink0•5 days agoAnd to further expand on that, if you do pass in a sting, it handles it correctly. > parseInt('0.0000005') 0
minus-square@AnotherPenguin@programming.devlinkfedilinkEnglish0•5 days agoMore like javascript L, even python would throw a TypeError for this example.
It’s because parseInt is expecting a string, so the decimal gets converted to a string, and
0.0000005.toString()
returns5e-7
.And to further expand on that, if you do pass in a sting, it handles it correctly.
> parseInt('0.0000005') 0
What if I pass in a Sterwart Copeland?
or a Honda civic
😆 I’ll be watching you…
Common Dynamic Typing L
More like javascript L, even python would throw a TypeError for this example.