Discuss Scratch
- Discussion Forums
- » Bugs and Glitches
- » Decimal Variable Glitch
- Waseypup
- Scratcher
70 posts
Decimal Variable Glitch
Hello
I am here to report a bug about decimal variable
Here is an example of what's happening:
and then sometimes (I will use 0.6 as an example) the variable will say it is “0.600000001”
I tried making it round:
But it would still report “”0.6000…01"
So i broke it down like this:
I have seen stuff kind of like this in java (double a=5; a == 5.00000000001) and before in scratch (examples above) but it is really annoying
I Need Help!
I am here to report a bug about decimal variable
Here is an example of what's happening:
repeat (100)
change [Counter v] by (0.1)
say (Counter)
wait (1) secs
end
and then sometimes (I will use 0.6 as an example) the variable will say it is “0.600000001”
I tried making it round:
set [Counter v] to ((round ((Counter) / (0.1))) * (0.1)) // << Rounding Method
But it would still report “”0.6000…01"
So i broke it down like this:
((Counter) / (0.1)) // (sometimes "5.999..9") Reports 6
(round (6)) // Reports 6
((6) * (0.1)) // Oddly Reports 0.6000...1
I have seen stuff kind of like this in java (double a=5; a == 5.00000000001) and before in scratch (examples above) but it is really annoying
I Need Help!
My browser / operating system: Windows NT 10.0, Chrome 91.0.4472.114, No Flash versions detected
Last edited by Waseypup (June 26, 2021 16:54:37)
- dhuls
- Scratcher
1000+ posts
Decimal Variable Glitch
floating point math(pretty sure that's the cause). Here's the fix though:Blame (src)when gf clicked
delete all of [e v] :: list
set [e v] to (0.1)
repeat (...)
add (e :: variables) to [e v]
replace item (length of [e v]) of [e v]with (([floor v] of ((e::variables)*(10)))/(10)
change [e v] by (0.1)
- Waseypup
- Scratcher
70 posts
Decimal Variable Glitch
floating point math(pretty sure that's the cause). Here's the fix though:Blame (src)when gf clicked
delete all of [e v] :: list
set [e v] to (0.1)
repeat (...)
add (e :: variables) to [e v]
replace item (length of [e v]) of [e v]with (([floor v] of ((e::variables)*(10)))/(10)
change [e v] by (0.1)
Interesting… I will try it!
But if i were using clones (which i am for this) would this be for this sprite only?
Last edited by Waseypup (June 26, 2021 17:10:33)
- Waseypup
- Scratcher
70 posts
Decimal Variable Glitch
floating point math(pretty sure that's the cause). Here's the fix though:Blame (src)when gf clicked
delete all of [e v] :: list
set [e v] to (0.1)
repeat (...)
add (e :: variables) to [e v]
replace item (length of [e v]) of [e v]with (([floor v] of ((e::variables)*(10)))/(10)
change [e v] by (0.1)
Ok, this is some mods of your bug fixer to make the scripts work… (Scripts Taken From My Project I Am Working On)
- Discussion Forums
- » Bugs and Glitches
- » Decimal Variable Glitch