Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Intergers only
- person78745476
- Scratcher
5 posts
Intergers only
I need my variables to only allow inters to be what it is, not to not allow decimals but to round it to the nearest whole number
- legendary34678
- Scratcher
1000+ posts
Intergers only
After setting your variable to a number, you could round it with the round block.
Can you beat my latest game?
Have you heard of the X Y Problem?
Please check out me projects please I'm desperate –> Idle Balls, Candy Grab!, Don't Move Your Mouse!, Rude Robot, Tic Tac Toe, Memory Game, Corn Maze, and Idle Balls PEN EDITION!
Oh, hey! I have 100+ posts now!
Oh, hey! I have 500+ posts now! (8/26/22)
Oh, hey! I have 1000+ posts now! (9/23/22)
(Thanks to @AntonL1kesPotato for helping me figure out how to add a signature!)
- Vaibhs11
- Scratcher
1000+ posts
Intergers only
There are three blocks that you could use:
You could also use the floor function just to remove the decimal part of a number.
(round (...)) // rounds to nearest integer: 1.75 => 2 // 1.25 => 1
([floor v] of (...)) // rounds to nearest integer below the number: 1.75 => 1 // 1.25 => 1
([ceiling v] of (...)) // rounds to the nearest integer above the number: 1.75 => 2 // 1.25 => 2
You could also use the floor function just to remove the decimal part of a number.
- MrKingofScratch
- Scratcher
100+ posts
Intergers only
(this post just combines the ones above by Vaibhs11 and legendary34678)
Every time you update the variable, you could do
alternatively whenever adding to the variable just include a round block
Every time you update the variable, you could do
set [var v] to (round (var))
alternatively whenever adding to the variable just include a round block
change [var v] by (round (equation here))
- person78745476
- Scratcher
5 posts
Intergers only
thank you that worked There are three blocks that you could use:(round (...)) // rounds to nearest integer: 1.75 => 2 // 1.25 => 1
([floor v] of (...)) // rounds to nearest integer below the number: 1.75 => 1 // 1.25 => 1
([ceiling v] of (...)) // rounds to the nearest integer above the number: 1.75 => 2 // 1.25 => 2
You could also use the floor function just to remove the decimal part of a number.
- Discussion Forums
- » Help with Scripts
- » Intergers only