473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 7217
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jack | last post by:
I have a problem that I can't seem to solve. I have checked the round, ceil and floor functions and they don't seem to do what I want. I have an entry like this <?php $tax = .065; $ad2day =...
9
by: joeandtel | last post by:
If I have a value that is 53.123499999, how can I round it to 53.12?
8
by: Schklerg | last post by:
I have this script performing a calculation on a page on my site: <script language="JavaScript"> function compute_weight(form) { var weight = form.wt.value; var pgs = form.pgs.value; var ppi =...
2
by: Matias Silva | last post by:
Can anybody tell me why I am getting rounding errors using the ROUND function. 3.7125 rounds to 3.70 when I use the following: TRUNCATE(ROUND(units_pay_amount * fees_amount, 2),2))) The correct...
10
by: tmeister | last post by:
I'm trying to determine the best approach for rounding in an application I'm building. Unfortunately it appears as though SQL Server and VB.NET round in different ways. SQL Server select...
6
by: Paul | last post by:
I can't round my numbers. i have a single, and i'm trying to round it so that there's only one decimal place. here's what i've tried: ..Val = CStr(Format(sngTimeToTarget, "#0.0")) and i also...
36
by: Phat G5 (G3) | last post by:
Has anyone found a reliable way to force JS to round to a specific number of places? Every time I try I get different results. For example, I'd need to round 3.4589 to 2 places. What is the most...
10
by: David Coleman | last post by:
I am running VS 2003 and have applied SP1. (On WinXP SP2, .Net 1.1) In the Command Window I get the following ? Math.Round(0.715, 2) 0.72 ? Math.Round(0.725, 2) 0.72 ? Math.Round(0.735, 2)...
4
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.