Eng:Round () (block)

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 roundedthis block will do the job.

Some common uses for the Round block are below: define calculate if <(operator) = [addition]> set [answer v] to ((value1) + (value2)) end if <(operator) = [round]> set [answer v] to (round (value)) end ...
 * Calculators that will let users round numbers

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

Workaround
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) or if <(n) > (0)> then set [rounded v] to (((n) + (0.5)) - (((n) + (0.5)) mod (1))) else set [rounded v] to ((((n) - (0.5)) - (((n) - (0.5)) mod (1))) + (1)) end 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) end if <<(letter (count) of (num)) = [.]> and <(letter ((count) + (1)) of (num)) > [4]>> then change [report v] by (1) end

Suggestions
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:



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. It would look like this: ([round v] of )