473,405 Members | 2,167 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.

1.090516455488E9 / 1000000.000 ???

Hello,

I got a simple and probably stupid newby question..
When I compute:
1.090516455488E9 / 1000000
the result is 1090516455.49
Should be 1090516455.488

I know something with float and //...

Anybody?
How do I get correct number?
Mar 28 '06 #1
2 1040
Math wrote:
Hello,

I got a simple and probably stupid newby question..
When I compute:
1.090516455488E9 / 1000000
the result is 1090516455.49
Should be 1090516455.488

I know something with float and //...

Anybody?
How do I get correct number?


Python 2.4.2 (#1, Mar 12 2006, 00:14:41)
[GCC 3.4.5 (Gentoo 3.4.5-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
1.090516455488E15 / 1000000 1090516455.4879999 print 1.090516455488E15 / 1000000

1090516455.49

print is using str() which formats the float number with 12 digits
precision and therefore rounds the result.
repr() however, which is used by the interpreter when printing
out expression results, uses 17 digits precision which is why
you can see how the result is stored in the computer's memory
(1090516455.487999999999999....).

Georg
Mar 28 '06 #2
Math <ma*********@home.nl> wrote:
I got a simple and probably stupid newby question..
When I compute:
1.090516455488E9 / 1000000
the result is 1090516455.49
Should be 1090516455.488

I know something with float and //...


http://www.python.org/doc/faq/genera...-so-inaccurate

Eg
a=1.090516455488E9 / 1000000
print a 1090.51645549 print repr(a) 1090.516455488
If you want a given number of decimal places you can use a formatter,
eg
print "%.20f" % a

1090.51645548800001961354

--
Nick Craig-Wood <ni**@craig-wood.com> -- http://www.craig-wood.com/nick
Mar 28 '06 #3

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

Similar topics

10
by: Ivan Voras | last post by:
Are there any performance/size differences between using tuples and using lists? -- -- Every sufficiently advanced magic is indistinguishable from technology - Arthur C Anticlarke
25
by: Brian Patterson | last post by:
I have noticed in the book of words that hasattr works by calling getattr and raising an exception if no such attribute exists. If I need the value in any case, am I better off using getattr...
9
by: Nico Grubert | last post by:
Hi there, Background of this question is: I want to convert all words <word> except 'and' / 'or' / 'and not' from a string into '*<word>*'. Example: I have the following string: "test and...
1
by: MyHaz | last post by:
What is the running time of conactination on character strings. i.e. >> joe="123" >> joe+="99999999999999999" is it Amortized Constant time? I don't think it would be O((number of...
16
by: Sreekanth | last post by:
Hello, Is there any better collection than HashTable in terms of performance, when the type of the key is integer? Regards, Sreekanth.
3
by: Caffiend | last post by:
This question is probably to complex to be answered quickly, but if you could even point me in the right direction that would be great! I am interested in knowing how to work with extremely large...
11
by: rshepard | last post by:
I start with a list of tuples retrieved from a database table. These tuples are extracted and put into individual lists. So I have lists that look like this: . When I concatenate lists, I end up...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
11
by: cjt22 | last post by:
Hi startswith( prefix]) States: Return True if string starts with the prefix, otherwise return False. prefix can also be a tuple of suffixes to look for. However when I try and add a tuple...
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.