Message78671
FYI, there is already a lossless implementation in the docs:
def float_to_decimal(f):
"Convert a floating point number to a Decimal with no loss of
information"
n, d = f.as_integer_ratio()
with localcontext() as ctx:
ctx.traps[Inexact] = True
while True:
try:
return Decimal(n) / Decimal(d)
except Inexact:
ctx.prec += 1 |
|
Date |
User |
Action |
Args |
2009-01-01 00:43:09 | rhettinger | set | recipients:
+ rhettinger, steven.daprano |
2009-01-01 00:43:09 | rhettinger | set | messageid: <1230770589.56.0.572003566636.issue4796@psf.upfronthosting.co.za> |
2009-01-01 00:43:08 | rhettinger | link | issue4796 messages |
2009-01-01 00:43:08 | rhettinger | create | |
|