Discuss Scratch

1Draven
Scratcher
100+ posts

math glitch

My browser / operating system: ChromeOS 14695.173.0, Chrome 102.0.0.0, No Flash version detected
(removed by moderator - for safety, please don't link to google drive stuff)
for some odd reason the numbers aren't adding together correctly and it's making a huge decimal

Last edited by Paddle2See (March 10, 2023 20:01:21)

CoconutGator
Scratcher
1000+ posts

math glitch

The issue is likely due to floating point errors. Doing many different operations with numbers can sometimes cause them to be very very slightly inaccurate.
also please don't post google drive links
medians
Scratcher
1000+ posts

math glitch

This is due to floating point errors.
What I mean is this:
Example:

Expected:

Actual:

This is due to how computers compute float numbers.

Last edited by medians (March 10, 2023 23:24:00)

10data10
Scratcher
100+ posts

math glitch

And you didn’t say if this was a problem for you or not so this post might be a waste. But just in case here’s one solution

From the Workarounds topic by _nix https://scratch.mit.edu/discuss/topic/611582/
define round (number) to (digits) decimal digits
set [rounded v] to ((round ((number) * ([10 ^ v] of (digits)))) / ([10 ^ v] of (digits))

So,

set [digits v] to [2]
if <((round (((0.1) + (0.2)) * ([10 ^ v] of (digits)))) / ([10 ^ v] of (digits))) = [.3]> then
say [No Money for Peter]
end
1Draven
Scratcher
100+ posts

math glitch

I know what floating points things are cuz I watched YouTube video on it but I was just saying because I found it was weird there you don't really need it help me I'm making it undertale game I don't really need to fix floating point approximation that much so yeah but thank thank you I guess






















































EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEE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