Decimals aren’t add-able

This bug causes decimals to glitch when being added, I don’t know the extent to this but here is a project showcase

The prompt is set to show 0.1 + 0.2, which is 0.3, but the prom-t shows a really long decimal. This happens without the show prompt block as well.

7 Likes

there is no such number as 0.1, you are being lied to.

𝓣𝓱𝓮𝓻𝓮 𝓲𝓼 𝓷𝓸 𝓮𝓼𝓬𝓪𝓹𝓮

11 Likes

oh noes it’s coalescing to string without rounding first

aside from that, we love floating point rounding errors. I thought it used to not be like that for some reason, but there are definitely past bug reports with similar issues so maybe it always has been, idk.

6 Likes

I dont understand that, petrichor’s answer makes much more sense! /hj

5 Likes

The .0 repeater 4 is a floating point error in JS

alert(0.1+0.2)

Will output 0.30000000000000004 lol

edit: wait why did the first part disappear lol

3 Likes

lol classic javascript error
welcome to the world of weird things of js @StarlightStudios!

4 Likes

Yeah, it’s super weird why JavaScript doesn’t even know how to do basic math when it comes to decimal numbers.

Only workaround is to multiply both numbers so they become whole numbers, add them, then divide them by the multiplier. (Easier said than done)…

Where’s Math.JS when you need it?

3 Likes

JavaScript should go back to school and re-learn how to add >:)

3 Likes

Iirc floating point numbers cant be precisely stored in binary, thus the weird results

3 Likes

If that were the case, wouldn’t the calculator apps also have those floating point rounding errors?

3 Likes

It was likely there the entire time, we just haven’t noticed it until the day we got the show pop-up block (since the block doesn’t round to the nearest 6 digits like most other blocks)…

3 Likes

Ugh so this isn’t even hopscotches fault?

2 Likes

no, blame the IEEE

3 Likes

Calculators do decimal operations, js and most languages do binary operations

1 Like

Then what does Math.JS do?

2 Likes

idk, the source is minified so I cant really check

Edit: what function are you specifically referring to? From what i can see, it is truncated to 14 decimal spaces max, which chops off the floating point error.

1 Like

I know many math libraries actually use strings to store the numbers so they don’t have to deal with precision loss, then return it back to you as a number when you want a final result

Not sure if Math.JS takes this approach, but if I had to guess, I think it would.

3 Likes

What if you add the round purple thing with the 0.2 and 0.1

2 Likes

Then it turns to 0 lol

2 Likes

Really?

Well that’s annoying

2 Likes