Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » What do the ceiling and floor operators do
- aeaeaeaeeaea
-
20 posts
What do the ceiling and floor operators do
Can someone please tell me what they do to a number / what their function is
- crumbthehog
-
92 posts
What do the ceiling and floor operators do
ceiling rounds up to the closest number. (1.2 = 2, 2.9 = 3 99.01 = 100 ) floor rounds down ( 1.9 = 1 51.99999. = 51 74.2 = 74)
- Spentine
-
1000+ posts
What do the ceiling and floor operators do
You know how you can round up and round down a number? Rounding down is what the floor operator does, and rounding up is what the ceiling operator does.
If you want to round 0.5 down to the nearest integer, then use floor(0.5). It will round down to 0.
If you want to round 0.5 up to the nearest integer, then use ceiling(0.5). It will round up to 1.
If the number is already an integer, like 5, then it will be the same, because rounding in any direction from 5 to the nearest integer is still 5, because 5 is an integer.
If you want to round 0.5 down to the nearest integer, then use floor(0.5). It will round down to 0.
If you want to round 0.5 up to the nearest integer, then use ceiling(0.5). It will round up to 1.
If the number is already an integer, like 5, then it will be the same, because rounding in any direction from 5 to the nearest integer is still 5, because 5 is an integer.
- Discussion Forums
- » Help with Scripts
-
» What do the ceiling and floor operators do