I am trying to overcome the flaws of sub-classing Python's float by using a different class hierarchy of numbers. However the following code:
from sympy import *
import sympy.core.numbers
f = 1.123456789
n = N(f, 8)
print n
print type(n)
sympy.core.numbers.Float.__str__ = lambda f: "{:.8f}".format(f)
print n
yields the error:
AttributeError: 'module' object has no attribute 'numbers'
How can I overcome this?
This does what you need:
Code:
from sympy.core.numbers import Float
Float.__str__ = lambda f: "{:.8f}".format(float(f))
Test Code:
from sympy import N
from sympy.core.numbers import Float
f = 1.123456789
n = N(f, 8)
Float.__str__ = lambda f: "{:.8f}".format(float(f))
print n
Results:
1.12345679
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With