round not rounding to 0 places

F

Fuzzydave

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
 
S

Sybren Stuvel

Fuzzydave enlightened us with:
round('+value+', 0)

4.97 is returned as 5.0 when i want it returned as 5

round returns a float. Use

int(round('+value+', 0))

to get an integer.

Sybren
 
S

Simon Forman

Fuzzydave said:
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?
 
T

Tim Leslie

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.
 
F

Fuzzydave

Sybren said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,263
Messages
2,571,062
Members
48,769
Latest member
Clifft

Latest Threads

Top