this post was submitted on 05 May 2025
499 points (100.0% liked)

Programmer Humor

24948 readers
1676 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
[–] [email protected] 85 points 2 months ago (13 children)

Yup. parseInt is for strings.
Math.floor, Math.ceil, Math.round or Math.trunc are for numeric type "conversions" (cause its still a float)

[–] [email protected] 50 points 2 months ago* (last edited 2 months ago) (12 children)

Nah, it's stupid either way.

"5e-7" is not an int to be parsed. Neither is "0.5".

[–] [email protected] 8 points 2 months ago* (last edited 2 months ago) (3 children)

Ah, folly of untyped systems. Tbh this behaviour makes sense given the rules implemented within the language. Anything passed to parseInt is casted to string and then parsed.

Is it shitty behaviour - yes. Does it make sense in given the language implementation - yes.

[–] [email protected] 3 points 2 months ago (1 children)

With this reasoning, would you say everything that a computer does makes sense, because it always follows the implementation? Or am I missing something?

[–] [email protected] 2 points 2 months ago

Bar space-level problem where radiation can randomly shift your bits, I think yes.

load more comments (1 replies)
load more comments (9 replies)
load more comments (9 replies)