By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 448,538 Members | 875 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,538 IT Pros & Developers. It's quick & easy.

# float64 print digits

 P: n/a I need a pytho nscript to read numbers(with loads of digits) from a file, do some basic math on it and write the result out to another file. My problem: I don't get python to use more digits: In order to try this I type: The normal precision one: >>from numpy import *x=1.23456789123456789123456789print "%35.25e" %x 1.2345678912345679000000000e+000 Now I try to use float64 to get more digits >>z=zeros(3,float64)z[0] 0.0 >>type(z[0]) >>z[0]=1.23456789123456789123456789type(z[0]) >>print "%35.25e" %z[0] 1.2345678912345679000000000e+000 This cuts the digits just like the 32bit case. Can anyone please help me get more digits? Thank you very much in advance, Ulrich Mar 2 '07 #1
Share this Question
2 Replies

 P: n/a Ulrich Dorda wrote: [Warning: I'm no expert and don't have numpy installed] I need a pytho nscript to read numbers(with loads of digits) from a file, do some basic math on it and write the result out to another file. My problem: I don't get python to use more digits: In order to try this I type: The normal precision one: >>from numpy import * >>x=1.23456789123456789123456789 >>print "%35.25e" %x 1.2345678912345679000000000e+000 Now I try to use float64 to get more digits >>z=zeros(3,float64) >>z[0] 0.0 >>type(z[0]) >>z[0]=1.23456789123456789123456789 The right side of the assignment is a float, so the extra digits would already be lost before you get a chance to convert to float64. But then Python's float is a C double and should already use 64 bits... >>type(z[0]) >>print "%35.25e" %z[0] 1.2345678912345679000000000e+000 This cuts the digits just like the 32bit case. Can anyone please help me get more digits? gmpy? Peter Mar 2 '07 #2

 P: n/a On 2007-03-02, Ulrich Dorda from numpy import *x=1.23456789123456789123456789print "%35.25e" %x 1.2345678912345679000000000e+000 Now I try to use float64 to get more digits You're already using 64 bit floats (which have about 15 significant digits). >z=zeros(3,float64)z[0] 0.0 >type(z[0]) >z[0]=1.23456789123456789123456789type(z[0]) >print "%35.25e" %z[0] 1.2345678912345679000000000e+000 This cuts the digits just like the 32bit case. What 32-bit case? A 32-bit float only has 7-8 significant digits. Can anyone please help me get more digits? Use the decimal module? -- Grant Edwards grante Yow! What a at COINCIDENCE! I'm an visi.com authorized "SNOOTS OF THE STARS" dealer!! Mar 2 '07 #3

### This discussion thread is closed

Replies have been disabled for this discussion.