pricision of string.atof?
Elvis Chen
chene at cs.queensu.ca
Tue May 7 15:59:36 EDT 2002
Greetings,
I'm working on some numerical analysis that requires rather good precision
on calculation. In my project, I need to read some numbers from a file
and subsequently process it to give other results. However, I found that
string.atof doesn't always convert the read string to equivalent number.
For example, if I have
s = 'A 0.424\n'
splitline = string.split( s )
A = string.atof( splitline[1] )
then,
>>> A
0.42399999999999999
>>> print A
0.424
My question is, what is the TRUE value of A when I use it in calculation?
Is it indeed 0.424 or not? If not, what can I do to work around this
problem?
I'm using python 2.2 on Solaris (SunOS 5.8):
radius [3:51pm]>python
Python 2.2 (#5, Feb 2 2002, 15:09:55)
[GCC 2.95.2 19991024 (release)] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
thx in advance,
ECC
More information about the Python-list
mailing list