Ceil and round off | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Ceil and round off

What's the difference between math.ceil() and the round() functions... And where to use which of them...!!???

7th Apr 2024, 11:17 AM
Solo Soul
Solo Soul - avatar
2 Answers
+ 6
math.floor(): rounds down to the largest integer less than or equal to the given number. e.g. math.floor(5.4) = 5 math.floor(5.99) = 5 math.ceil(): rounds up to the smallest integer greater than or equal to the given number. e.g. math.ceil(4.01) = 5 math.ceil(4.8) = 5 math.round(): rounds to the nearest integer. e.g. math.round(3.2) = 3 math.round(3.5) = 4 math.round(3.6) = 4
7th Apr 2024, 1:17 PM
šŸ‡®šŸ‡± Radin Masiha šŸ‡®šŸ‡±
šŸ‡®šŸ‡± Radin Masiha šŸ‡®šŸ‡± - avatar
0
The math.ceil() function always rounds up to the nearest integer, while the round() function rounds to the nearest integer. If the number is exactly halfway between two integers, round() rounds to the nearest even number. Use math.ceil() when you always want to round up, and use round() for standard rounding to the nearest integer.
12th Apr 2024, 8:12 AM
`Š½Ń‚Ń‚pā“ā°ā¶
`Š½Ń‚Ń‚pā“ā°ā¶ - avatar