Round function gets two parameters, first one is variable type of real which is the number to be rounded and the other one is decimal which will be used as sensitivity constant. What does mean sensitivity? Let’s dive into examples.
- round(23.79, 0.1) = 23.80 . The explanation of the result is:
- Closest multiple to the number of 0.1 is on the left : 23.70 and on the right : 23.80. But the closest one is 23.80 ie. the result.
- Closest multiple to the number of 0.5 is on the left : 23.50 and on the right : 24.00. But the closest one is 24.00 ie. the result.
- Closest multiple to the number of 10 is on the left : 20.00 and on the right : 30.00. But the closest one is 20.00 ie. the result.
- Closest multiple to the number of 0.1 is on the left : 23.00 and on the right : 24.00. Which have equal distance to the number. In this case bigger one will be taken into account which is 24.00 ie. the result.
- Closest multiple to the number of 50 is on the left : 0.00 and on the right : 50.00. But the closest one is 0.00 ie. the result.
<<<<<<<<<<<<<<<<<<<<<< | >>>>>>>>>>>>>>>>>>>>>> |
Above shape shows behavior of round function. Thus, There are two boundaries, lower and upper, rounded number will be lower boundary if number is closer to lower boundary and vice versa. Special case the middle boundary ( (lower+upper) / 2 ), which the result will be upper one
No comments:
Post a Comment