By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,677 Members | 1,174 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,677 IT Pros & Developers. It's quick & easy.

round not rounding to 0 places

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.