Difference between .ceil() and .round()?

What is the difference between .ceil() & .round()

1 Like

ceil() rounds the number up, and round() rounds correctly depending on the number.
Similarly to ceil(), there is floor(), which always rounds down.

3 Likes

ceil (math ceiling) always rounds up (ceil(1.000000001) = 2) , round is normal rounding (i.e. round(1.499999) = 1 and round(1.5) = 2

1 Like
  • round() rounds a float value to the nearest integer . If either of the two integers on either side are equal distance apart, the even number is picked.Here, the nearest integer is always -6 ; for -5.5 the nearest even integer is -6 , not -5 .
  • math.ceil() returns the smallest integer greater than or equal to the float value.Here, the next integer greater than the inputs is always -5 (remember that negative numbers decrease away from zero).

https://stackoverflow.com/questions/48723451/why-do-round-and-math-ceil-give-different-values-for-negative-numbers-in-pyt#:~:text=The%20functions%20execute%20different%20mathematical,value%20to%20the%20nearest%20integer.&text=%2C%20not%20-5%20.-,math.,equal%20to%20the%20float%20value.

1 Like

Ceil will round the number to its immediate above number… round will round the number to its itself or immediate above number based on the decimal point…
Example:
We have number 12.3
Upon application of ceil it will become 13… which is immediate next num of 12…
If we apply round method , first it would check whether the digit after decimal point is greater than 5 or not…
If it is greater than 5,it will round it to immediate next number…
Ex:round(12.67) is 13…
If it is less then it will round number to itself…
Ex: round(12 .345) is 12…
if the immediate digit after decimal point is 5,then it go for next decimal digit…
Ex:round(12.57) as 7 >5 round(12.57) is 13…
NOTE: round(12.5) is 12…
Hope this helps…
If you feel strange plz ingnore it…
If I am wrong plz correct me…
Suggestions are always welcome…
Happy learning :blush::blush:

3 Likes

Math.ceil() and Math.round() methods differ in a way that the former round off a number to its nearest integer in upward direction of rounding(towards the greater value) whereas the latter round off a number to its nearest integer in downward direction of rounding(towards lower value)