468,719 Members | 1,798 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,719 developers. It's quick & easy.

round not rounding to 0 places

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

Aug 16 '06 #1
4 6859
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?

Aug 16 '06 #2
On 16 Aug 2006 00:19:24 -0700, Fuzzydave <Fu*******@gmail.comwrote:
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?
round returns a float. You probably want to convert it to an int.
>>int(round(4.97))
5

Cheers,

Tim
>
David P

--
http://mail.python.org/mailman/listinfo/python-list
Aug 16 '06 #3
Sybren Stuvel wrote:
round returns a float. Use
int(round('+value+', 0))
to get an integer.
Sybren
ahh of course it does, slaps own forehead sorted
thanks :)

David P

Aug 16 '06 #4
In article <ma***************************************@python. org>,
Tim Leslie <ti********@gmail.comwrote:
>On 16 Aug 2006 00:19:24 -0700, Fuzzydave <Fu*******@gmail.comwrote:
>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?

round returns a float. You probably want to convert it to an int.
>>>int(round(4.97))
5
Aug 16 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jack | last post: by
9 posts views Thread by joeandtel | last post: by
2 posts views Thread by Matias Silva | last post: by
10 posts views Thread by tmeister | last post: by
6 posts views Thread by Paul | last post: by
36 posts views Thread by Phat G5 (G3) | last post: by
10 posts views Thread by David Coleman | last post: by
4 posts views Thread by =?Utf-8?B?UmVuZQ==?= | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Oskars | last post: by
9 posts views Thread by bryonone | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.