@OsrsNeedsF2P@lemmy.ml to Programmer Humor@programming.dev • 1 month agoparseInt(5)lemmy.mlimagemessage-square66fedilinkarrow-up1497arrow-down10
arrow-up1497arrow-down1imageparseInt(5)lemmy.ml@OsrsNeedsF2P@lemmy.ml to Programmer Humor@programming.dev • 1 month agomessage-square66fedilink
minus-square@danda@lemmy.ziplinkfedilink100•1 month 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•1 month agoMore like javascript L, even python would throw a TypeError for this example.
minus-square@spizzat2@lemm.eelinkfedilink31•edit-21 month 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-21 month 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') 0
What if I pass in a Stewart Copeland?
😆 I’ll be watching you…
or a Honda civic