python round function

Table of Contents

The round() function returns the rounded floating point value number, rounded to ndigits digits after the decimal point. If ndigits is omitted, it defaults to zero.

Note: For the 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). The return value is an integer if called with one argument, otherwise of the same type as number.

Example

#int
print(round(12))
#float
print(round(86.6))
print(round(55.5))
print(round(92.4))

 

Output:

12
87
56
92

 

Leave a Comment

Your email address will not be published. Required fields are marked *

No data found.