Python float __setformat__? -
i have problem, need float correct upto 18 decimal places. when use default float(number), gives me 12 decimal places only.
then did dir(float)
['__abs__', '__add__', '__class__', '__coerce__', '__delattr__', '__div__', '__divmod__', '__doc__', '__eq__', '__float__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getformat__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__int__', '__le__', '__long__', '__lt__', '__m od__', '__mul__', '__ne__', '__neg__', '__new__', '__nonzero__', '__pos__', '__pow__', '__radd__', ' __rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rmod__', '_ _rmul__', '__rpow__', '__rsub__', '__rtruediv__', '__setattr__', '__setformat__', '__sizeof__', '__s tr__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', 'as_integer_ratio', 'conjugate', ' fromhex', 'hex', 'imag', 'is_integer', 'real']
there called __setformat__ in block. use? , how use floating point precision setting?
i using python 2.7.5 x64.
it of use python test suite; help(float.__setformat__)
prints:
float.__setformat__(typestr, fmt) -> none
you don't want use function. exists used in python's test suite.
typestr must
'double'
or'float'
. fmt must 1 of'unknown'
,'ieee, big-endian'
or'ieee, little-endian'
, , in addition can 1 of latter 2 if appears match underlying c reality.overrides automatic determination of c-level floating point type. affects how floats converted , binary strings.
there float.__getformat__()
well, getter method same information, same purpose.
see float
test suite more details on use.
use decimal
module more accurate decimal calculations, check out sys.float_info
details on how accurate floats on platform. 64bit mac os x system can manage 15 digits, example.
Comments
Post a Comment