0

Round function and some maths question i couldnt solve, help me to find error

When we going to round 'even value '+0.5 to a integer had a wrong value as a example when #round(2.5)=2 # round(1.5)=2 and also #round(2.45,1)=2.4 like this.... what is the reson for this? And also when a=2.356 #a%=0.356000000002 how it happen? Help me to solve these problems.

6th May 2020, 7:29 AM
Mahanama Gamage
Mahanama Gamage - avatar
1 Respuesta
+ 1
I believe the problem is round(2.5) = round(1.5) = 2, due to the fact that Round rounds up to an even number. The same occurs with round (3.5) and round (4.5) or round (-0.5) and round (0.5), return 4 and 0, respectively. If you want to differentiate your rounding, experiment with math and use the floor and ceil. ### import math print (math.floor(2.5), math.ceil(2.5)) #the answer will be 2 and 3 floor rounds down while ceil rounds up. in addition, there is a module called 'decimal' that can facilitate rounding. look here: https://docs.python.org/3/library/decimal.html#Rounding_modes
8th May 2020, 11:19 PM
Matheus Bonjour
Matheus Bonjour - avatar