this post was submitted on 05 May 2025
431 points (98.9% liked)

Programmer Humor

23040 readers
1896 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] danda@lemmy.zip 98 points 23 hours ago (2 children)

It's because parseInt is expecting a string, so the decimal gets converted to a string, and 0.0000005.toString() returns 5e-7.

[–] KindaABigDyl@programming.dev 39 points 22 hours ago (1 children)
[–] AnotherPenguin@programming.dev 4 points 9 hours ago

More like javascript L, even python would throw a TypeError for this example.

[–] spizzat2@lemm.ee 30 points 21 hours ago* (last edited 20 hours ago) (1 children)

And to further expand on that, if you do pass in a ~~sting~~ string, it handles it correctly.

> parseInt('0.0000005')

0
[–] SpaceNoodle@lemmy.world 16 points 20 hours ago* (last edited 5 hours ago) (2 children)

What if I pass in a Stewart Copeland?

[–] xtools@programming.dev 3 points 14 hours ago

or a Honda civic

[–] spizzat2@lemm.ee 7 points 20 hours ago

😆 I'll be watching you...