From Test-Scratch-Wiki

Round ()
2.0 Round ().png
Category Operator
Type Reporter

The Round () block is an Operators block and a Reporter block. The block rounds the given number to the nearest integer. It follows the standard rules of rounding; decimals that are .5 or higher are rounded up, whereas decimals less than .5 are rounded down.

Example Uses

In projects that handle decimal numbers, they may have to be rounded —this block will do the job.

Some common uses for the Round () block are below:

  • Calculators that will let users round numbers
define calculate
if <(operator) = [addition]>
set [answer v] to ((value1) + (value2))
if <(operator) = [round]>
set [answer v] to (round (value))

when this sprite clicked //calculator equivalent to the "=" button
  • Checking if numbers are approximately equal to each other
set [close? v] to <([abs v] of ((round (value1)) - (round (value2)))) < (2)> //one of many methods
  • Rounding a score to the nearest whole number in games
set [score v] to (round (score))
  • Removing the decimal from a score, without rounding up
set [score v] to (round ((score) - (0.5)))//any number minus 0.5 will round to the lower integer
  • Rounding the value to be put in the Repeat () block, since the value must be a whole number
repeat (round (2.3840462816))
when gf clicked
go to x: ((round ((mouse x) / (25))) * (25)) y: ((round ((mouse y) / (25))) * (25))


Main article: List of Block Workarounds

One can use the "Ceil" and "Floor" operations in Scratch 2.0 to accurately round a number:

([floor v] of ((number) + (0.5))) //round a number

The mathematical functions "floor" and "ceiling" can also be replicated using modular arithmetic:

((number) - ((number) mod (1))) //round down (floor)
((number) + ((1) - ((number) mod (1)))) //round up (ceiling)


if <(n) > (0)> then
set [rounded v] to (((n) + (0.5)) - (((n) + (0.5)) mod (1)))
set [rounded v] to ((((n) - (0.5)) - (((n) - (0.5)) mod (1))) + (1))

Another way to replicate the block is to use the letter () of () and join () () operator blocks.

set [report v] to [ ]
set [count v] to [0]
  repeat until <<(letter (count) of (num)) = [.]> or <(count) = (length of (num))>>
  set [report v] to (join (report) (letter (count) of (num)))
  change [count v] by (1)
if <<(letter (count) of (num)) = [.]> and <(letter ((count) + (1)) of (num)) > [4]>> then
  change [report v] by (1)


Some Scratchers want a reporter block which rounds to a certain number-place. The block would make all of the above uses more accurate. It would look like this:

<round (number) to the nearest (base) // category=operators

It can be replicated by shifting the number over (multiplying or dividing by 10), rounding, and then reversing the original operation.

((round ((number) * ([10^ v] of (number of places)))) / ([10^ v] of (number of places)))

or even this:

((round ((round what) / (to the nearest))) * (to the nearest))

Some Scratchers had suggested to update the (round ()) block as a function.[1] It would look like this:

([round v] of ())


Cookies help us deliver our services. By using our services, you agree to our use of cookies.