Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Round to nearest (num)?
- MarkGamez
-
Scratcher
31 posts
Round to nearest (num)?
So, i saw the round block
Then i noticed it rounds to the nearest whole number
Then i started wondering, Can i make it round to the nearest number of my choosing?
nope.
didnt work.
Can someone provide me with a script to round a number to the nearest number?
as in
(round (10))and, first i didnt know what it did,
Then i noticed it rounds to the nearest whole number
Then i started wondering, Can i make it round to the nearest number of my choosing?
nope.
didnt work.
Can someone provide me with a script to round a number to the nearest number?
as in
round () to the nearest ()
Last edited by MarkGamez (March 12, 2022 00:59:48)
- Scratch-Minion
-
Scratcher
1000+ posts
Round to nearest (num)?
To round to the nearest 10,
eg. Round 24.5 to the nearest 10,
Rounded Number = (Round (24.5/10)) * 10
= (Round 2.45) * 10
= 2 * 10
= 20
You can make this into a custom block rounding to numbers other than 10.
set [Rounded Number v] to ((round ((Number) / (10))) * (10))
eg. Round 24.5 to the nearest 10,
Rounded Number = (Round (24.5/10)) * 10
= (Round 2.45) * 10
= 2 * 10
= 20
You can make this into a custom block rounding to numbers other than 10.
- bcs320jn
-
Scratcher
100+ posts
Round to nearest (num)?
Maybe
if <((Number) - ((Number) - (letter (length of (Number)) of (Number)))) > [5]> then
set [return v] to ((Number) - (letter (length of (Number)) of (Number)))
else
set [return v] to ((Number) + ([10] - (letter (length of (Number)) of (Number))))
end
Last edited by bcs320jn (March 12, 2022 12:59:54)
- Discussion Forums
- » Help with Scripts
-
» Round to nearest (num)?