OsrsNeedsF2P@lemmy.ml to Programmer Humor@programming.dev · 21 hours agoparseInt(5)imagemessage-square59linkfedilinkarrow-up1425arrow-down15
arrow-up1420arrow-down1imageparseInt(5)OsrsNeedsF2P@lemmy.ml to Programmer Humor@programming.dev · 21 hours agomessage-square59linkfedilink
minus-squaredanda@lemmy.ziplinkfedilinkarrow-up98·21 hours agoIt’s because parseInt is expecting a string, so the decimal gets converted to a string, and 0.0000005.toString() returns 5e-7.
minus-squarespizzat2@lemm.eelinkfedilinkarrow-up30·edit-218 hours agoAnd to further expand on that, if you do pass in a sting string, it handles it correctly. > parseInt('0.0000005') 0
minus-squareSpaceNoodle@lemmy.worldlinkfedilinkarrow-up16·edit-23 hours agoWhat if I pass in a Stewart Copeland?
minus-squareKindaABigDyl@programming.devlinkfedilinkarrow-up40arrow-down1·20 hours agoCommon Dynamic Typing L
minus-squareAnotherPenguin@programming.devlinkfedilinkEnglisharrow-up4·7 hours 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
stingstring, it handles it correctly.> parseInt('0.0000005') 0
What if I pass in a Stewart 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.