r/programminghorror • • Jun 12 '25 • This 1

Javascript Javascript is filled with horror

Post image
2.4k Upvotes

337 comments sorted by

View all comments

Show parent comment

1

u/Altruistic-Formal678 Jun 14 '25

What it should do ? Mostly in this case, it is use to round number. But really it is not really used with decimals like this.

In this case: Integer.parse expect a string, so it parse 0.0000005 to string, which is "5.10e-7" and Integer.parse("5.10e-7") only takes the last character that is number, thus 7

1

u/CuAnnan Jun 14 '25

Integer.parse doesn't round.

That would be what Math.round is for.

It parses a string to an integer.

1

u/CuAnnan Jun 14 '25

Also, on reflection (and it's 00:15 here so I need a little latitude).

Integer.parse is java.

parseInt parses a String to an integer.

It doesn't round

parseInt(1.7) returns 1

1

u/Altruistic-Formal678 Jun 15 '25

It truncate, sorry, I mixed up. Also I never said I was a JS expert, I was just looking for the silly quizz