round() returns different result depending on the number of arguments

The round function returns an integer if the second argument is not specified, else the return value has the same type as that of the first argument:

>>> help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. Otherwise
    the return value has the same type as the number. ndigits may be negative.

So if the arguments passed are an integer and a zero, the return value will be an integer type:

>>> round(100, 0)
100
>>> round(100, 1)
100

For the sake of completeness:

Negative numbers are used for rounding before the decimal place

>>> round(124638, -2)
124600
>>> round(15432.346, -2)
15400.0

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)