round(a) returns a number which is the closest integer of a.

The function rounds the number up, if the first decimal place is 5 or higher. The functions rounds the number down, if the first decimal place is 4 or lower.

For example:

round(4.7) = 5

round(13.5) = 14

round(8.3) = 8

round(14.0) = 14

Where can you use the round function?

We would like to write a program, where an object says how old it is. The age is calculated by the current year - publishing year of Pocket Code (2010). First we set a variable "Rounding" to round( year + ((month - 1) / 12) + ((day - 1) / 365)). This variable returns a float number of the current year. For example 2018,5 means the current year is 2018 but the first halve has already passed. Then we need an If clause that checks if the variable Rounding equals year - 2010. If this is true, the object says "I am [actual age of the object] years old." If this is not true, the object says "I will be [age of the object + 1] in the near future."

Code:

round_english_bearbeitet_bearbeitet.png

ccbysa.png