Function Details: round

Description


Rounds a number to a given precision in decimal digits.


Extended Description


The round() function returns the number rounded to ndigits precision after the decimal point. If ndigits is omitted or is None, it returns the nearest integer to its input. For built-in types supporting round(), values are rounded to the closest multiple of 10 to the power minus ndigits; if two multiples are equally close, rounding is done toward the even choice (so, for example, both round(0.5) and round(-0.5) are 0, and round(1.5) is 2).


Read More about round from Python Documentation

Function Signature


round(number: Union[int, float], ndigits: Optional[int] = None) -> Union[int, float]

Module: builtins

Parameters



Parameter List


  • number: Union[int, float]
  • ndigits: Optional[int]

Return


Returns the rounded number. The result is an integer if ndigits is omitted or None. Otherwise, the result has the same type as the input.


Return Type


Union[int, float]

Output

Explanation

These examples show basic usage of round() with different precisions and demonstrate the 'round to even' rule for .5 cases.