Advertisement
rfmonk

fractions_from_decimal.py

Jan 22nd, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.26 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import decimal
  5. import fractions
  6.  
  7. for v in [decimal.Decimal('0.1'),
  8.           decimal.Decimal('0.5'),
  9.           decimal.Decimal('1.5'),
  10.           decimal.Decimal('2.1'),
  11.           ]:
  12.     print '%s = %s' % (v, fractions.Fraction.from_decimal(v))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement