@OsrsNeedsF2P@lemmy.ml to Programmer Humor@programming.dev • 6 months agoparseInt(5)lemmy.mlimagemessage-square65fedilinkarrow-up1506arrow-down16
arrow-up1500arrow-down1imageparseInt(5)lemmy.ml@OsrsNeedsF2P@lemmy.ml to Programmer Humor@programming.dev • 6 months agomessage-square65fedilink
minus-square@danda@lemmy.ziplinkfedilink102•6 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@AnotherPenguin@programming.devlinkfedilinkEnglish5•6 months agoMore like javascript L, even python would throw a TypeError for this example.
minus-square@spizzat2@lemm.eelinkfedilink31•edit-26 months agoAnd to further expand on that, if you do pass in a sting string, it handles it correctly. > parseInt('0.0000005') 0
minus-square@SpaceNoodle@lemmy.worldlinkfedilink18•edit-26 months agoWhat if I pass in a Stewart Copeland?
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') 0What if I pass in a Stewart Copeland?
😆 I’ll be watching you…
or a Honda civic