473,569 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7235
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*******@gmai l.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.9 7))
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('+val ue+', 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************ *************** ************@py thon.org>,
Tim Leslie <ti********@gma il.comwrote:
>On 16 Aug 2006 00:19:24 -0700, Fuzzydave <Fu*******@gmai l.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
4394
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 = 104.50; $ad2day = round(($ad2day * $tax)+ $ad2day, 2);
9
4744
by: joeandtel | last post by:
If I have a value that is 53.123499999, how can I round it to 53.12?
8
4320
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 = form.ppi.value; var hite = form.ht.value; if (weight > 0.0) { form.totwid.value = int_zero( weight * 2 )+(pgs/ppi)+0.5;
2
3106
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 value should be 3.71 I could round to the 3rd decimal place ROUND(X,3) and that would round it correctly to 3.71 but that would mean I would...
10
12932
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 round(123.465,2) returns
6
1500
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 tried ..Val = CStr(round(CDbl(sngTimeToTarget), 1)) neither of which do anything. i've even tried multiplying by 10, coercing to an integer,...
36
5837
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 reliable way to do it? Thanks -S
10
15994
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) 0.74
4
10878
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
7694
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7666
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6278
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.