Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # credit for this goes to the author
- # of The Python Standard Library by example
- # Jesse Noller, Python Core Developer and PSF Board Member
- # Book can be purchased on amazon, it is also
- # on the oreilly bookshelf and may be at your
- # library. I'm only reprinting the code example
- # here because I'm working on this stuff as a
- # student of the Python Programming language.
- # Thanks Jesse Noller for such a good book.
- import decimal
- fmt = '{0:<25} {1:<25}'
- print fmt.format('Input', 'Output')
- print fmt.format('-' * 25, '-' * 25)
- # Integer
- print fmt.format(5, decimal.Decimal(5))
- # String
- print fmt.format('3.14', decimal.Decimal('3.14'))
- # Float
- f = 0.1
- print fmt.format(repr(f), decimal.Decimal(str(f)))
- print fmt.format('%23g' % f,
- str(decimal.Decimal.from_float(f))[:25])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement