round not rounding to 0 places

Simon Forman rogue_pedro at yahoo.com
Wed Aug 16 03:42:15 EDT 2006


Fuzzydave wrote:
> I have been using a round command in a few places to round
> a value to zero decimal places using the following format,
>
> round('+value+', 0)
>
> but this consistantly returns the rounded result of the value
> to one decimal place with a zero
>
> EG:
>
> 4.97 is returned as 5.0 when i want it returned as 5, does
> anyone know why this is and if i can get the round to make
> the value 5?
>
> David P

|>> n = 4.97
|>> round(n)
5.0
|>> int(round(n))
5
|>> help(round)
Help on built-in function round in module __builtin__:

round(...)
    round(number[, ndigits]) -> floating point number

    Round a number to a given precision in decimal digits (default 0
digits).
    This always returns a floating point number.  Precision may be
negative.


HTH,
~Simon


BTW, '+value+' ..?  Huh?




More information about the Python-list mailing list