OsrsNeedsF2P@lemmy.ml to Programmer Humor@programming.dev · 12 days agoparseInt(5)lemmy.mlexternal-linkmessage-square61fedilinkarrow-up11arrow-down10
arrow-up11arrow-down1external-linkparseInt(5)lemmy.mlOsrsNeedsF2P@lemmy.ml to Programmer Humor@programming.dev · 12 days agomessage-square61fedilink
minus-squaredanda@lemmy.ziplinkfedilinkarrow-up0·12 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-squarespizzat2@lemm.eelinkfedilinkarrow-up0·12 days agoAnd to further expand on that, if you do pass in a sting, it handles it correctly. > parseInt('0.0000005') 0
minus-squareSpaceNoodle@lemmy.worldlinkfedilinkarrow-up0·12 days agoWhat if I pass in a Sterwart Copeland?
minus-squareAnotherPenguin@programming.devlinkfedilinkEnglisharrow-up0·11 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?
😆 I’ll be watching you…
or a Honda civic
Common Dynamic Typing L
More like javascript L, even python would throw a TypeError for this example.