OsrsNeedsF2P ( OsrsNeedsF2P@lemmy.ml ) to Programmer Humor@programming.dev · 1 year agoparseInt(5)lemmy.mlexternal-linkmessage-square25linkfedilinkarrow-up1302
arrow-up1302external-linkparseInt(5)lemmy.mlOsrsNeedsF2P ( OsrsNeedsF2P@lemmy.ml ) to Programmer Humor@programming.dev · 1 year agomessage-square25linkfedilink
minus-squaredanda ( danda@lemmy.zip ) linkfedilinkarrow-up67·1 year agoIt’s because parseInt is expecting a string, so the decimal gets converted to a string, and 0.0000005.toString() returns 5e-7.
minus-squareKindaABigDyl ( KindaABigDyl@programming.dev ) linkfedilinkarrow-up31·1 year agoCommon Dynamic Typing L
minus-squareAnotherPenguin ( AnotherPenguin@programming.dev ) linkfedilinkEnglisharrow-up3·1 year agoMore like javascript L, even python would throw a TypeError for this example.
minus-squarespizzat2 ( spizzat2@lemm.ee ) linkfedilinkarrow-up17·edit-21 year agoAnd to further expand on that, if you do pass in a sting string, it handles it correctly. > parseInt('0.0000005') 0
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