Python - Rounding, Banker's Rounding (round, math.ceil, math.floor, math.trunc) Tutorial

preview_player
Показать описание
In depth tutorial of rounding with Python, geared to beginners. Discussion of the built-in round function, as well as getting ceilings, floors, and truncating numbers using Python's math module. Includes discussion of why numbers ending in .5 sometimes rounds up and sometimes rounds down (i.e. Banker's Rounding, aka Dutch Rounding or Gaussian rounding), and a couple of different ways to get numbers ending in .5 to always round up instead. Time stamps are below.

round() - 0:22
Why do numbers ending in .5 sometimes round down and sometimes round up? (Banker's Rounding (rounding to the nearest even result)) - 1:34
round() to specified number of digits - 6:25
round() to "None" number of digits - 7:37
round() using expressions inside the parenthesis - 9:32
Can you round infinity or "not a number"? - 13:05
Taking ceiling of negative number - 15:59
Can you truncate "infinity" or "not a number"? - 23:57
Рекомендации по теме
Комментарии
Автор

I came here for understanding round() function. Excellent explanation, now everything is clear. Thank you!

mihaelasava
Автор

Very Very Helpful Bro...Thank You Too Most...🥳💫🥳💫🥳💫

onkarkulkarni
Автор

to be fair, it is not a choice of python, it is the standard in IEEE 754 for rounding numbers.

legion_prex
Автор

round(5.65, 1) should round to 5.6, right? But it does round up to 5.7. Who knows why?

legion_prex
Автор

How can I round to the nearest integer?

albaraa_