473,385 Members | 1,400 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,385 software developers and data experts.

ROUNDING???

in python im doing the problem 255/494

it keeps giving me 0 instead of .51....
what am i doing wrong?

please help me I have been looking for hours
__________________________________________________ __________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs

Feb 19 '08 #1
5 1719
On Feb 18, 7:57*pm, katie smith <iceboy...@yahoo.comwrote:
in python im doing the problem 255/494

it keeps giving me 0 instead of .51....
what am i doing wrong?

please help me I have been looking for hours

* * * __________________________________________________ _________________________ _________
Never miss a thing. *Make Yahoo your home page.http://www.yahoo.com/r/hs
An integer divided by an integer produces an integer. In computer
programming, that's called 'integer arithmetic', and any fractional
part of the result is chopped off(not rounded). If your arithmetic
involves at least one float, then you will get a float as an asnwer:
print 255/494
print 255.0/494
print (255 * 1.0)/494

--output:--
0
0.516194331984
0.516194331984
Feb 19 '08 #2
7stud wrote:
On Feb 18, 7:57 pm, katie smith <iceboy...@yahoo.comwrote:
>in python im doing the problem 255/494

it keeps giving me 0 instead of .51....
what am i doing wrong?

please help me I have been looking for hours

__________________________________________________ _________________________ _________
Never miss a thing. Make Yahoo your home page.http://www.yahoo.com/r/hs

An integer divided by an integer produces an integer. In computer
programming, that's called 'integer arithmetic', and any fractional
part of the result is chopped off(not rounded). If your arithmetic
involves at least one float, then you will get a float as an asnwer:
print 255/494
print 255.0/494
print (255 * 1.0)/494

--output:--
0
0.516194331984
0.516194331984
Not that this behavior is expected to change in the future, such that
255 / 494 will actually perform floating-point division. The way to
achieve flooring division will be 255 // 494.
Feb 19 '08 #3
In article <ma*************************************@python.or g>,
katie smith <ic*******@yahoo.comwrote:
>
in python im doing the problem 255/494

it keeps giving me 0 instead of .51....
what am i doing wrong?
>>from __future__ import division
2/5
0.40000000000000002

In addition:
>>division
_Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)

Therefore this works in Python 2.2 and higher.
--
Aahz (aa**@pythoncraft.com) <* http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of
indirection." --Butler Lampson
Feb 19 '08 #4
You can use the round() function. And if you want to print, use %0.2f
regards,
Subeen.
http://love-python.blogspot.com/
On Feb 19, 9:36 am, a...@pythoncraft.com (Aahz) wrote:
In article <mailman.949.1203389866.9267.python-l...@python.org>,
katie smith <iceboy...@yahoo.comwrote:
in python im doing the problem 255/494
it keeps giving me 0 instead of .51....
what am i doing wrong?
>from __future__ import division
2/5

0.40000000000000002

In addition:
>division

_Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)

Therefore this works in Python 2.2 and higher.
--
Aahz (a...@pythoncraft.com) <* http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of
indirection." --Butler Lampson
Feb 19 '08 #5
On Feb 19, 2:05 pm, 7stud <bbxx789_0...@yahoo.comwrote:
An integer divided by an integer produces an integer. In computer
programming, that's called 'integer arithmetic', and any fractional
part of the result is chopped off(not rounded).
In case you care, the "chopped off" bit is given by the modulo
operator '%'. So integer division x/y is really like the everyday y
goes into x, p times, remainder q, for example:
>>10/3, 10%3
(3, 1)
If your arithmetic
involves at least one float, then you will get a float as an asnwer:

print 255/494
print 255.0/494
print (255 * 1.0)/494
or indeed "print float(255)/494"
Feb 19 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Norvin Laudon | last post by:
Hi, Can somebody explain the following, from the MSDN documentation for the "System.Convert.ToInt32(double)" function <quote> Return Value value rounded to the nearest 32-bit signed...
4
by: spebola | last post by:
I am using vb.net 2003 professional and I get the following results when using the round method: dim Amount as decimal = 180.255 Amount = Amount.Round(Amount, 2) Amount now contains 180.25. ...
8
by: Zorpiedoman | last post by:
Howcome: Dim D as decimal = .5D msgbox d.Round(D, 0) this returns "0" Now when I went to school .5 rounds UP to 1 not DOWN to zero?????!!! Documentation says this, but what the heck are...
2
by: Jiri Nemec | last post by:
Hello all, I have got one table with rounding values, table contains prices and round types. id price_from price_to rounding 1 0 1500 0.1 2 1500 ...
11
by: cj | last post by:
Lets assume all calculations are done with decimal data types so things are as precise as possible. When it comes to the final rounding to cut a check to pay dividends for example in VB rounding...
18
by: jdrott1 | last post by:
i'm trying to round my currency string to end in 9. it's for a pricing application. this is the function i'm using to get the item in currency: FormatCurrency(BoxCost, , , , TriState.True) if...
5
by: Spoon | last post by:
Hello everyone, I don't understand how the lrint() function works. long lrint(double x); The function returns the nearest long integer to x, consistent with the current rounding mode. It...
206
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
20
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
30
by: bdsatish | last post by:
The built-in function round( ) will always "round up", that is 1.5 is rounded to 2.0 and 2.5 is rounded to 3.0. If I want to round to the nearest even, that is my_round(1.5) = 2 # As...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.