Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import decimal
- context = decimal.getcontext()
- ROUNDING_MODES = [
- 'ROUND_CEILING',
- 'ROUND_DOWN',
- 'ROUND_FLOOR',
- 'ROUND_HALF_DOWN',
- 'ROUND_HALF_EVEN',
- 'ROUND_HALF_UP',
- 'ROUND_UP',
- 'ROUND_05UP',
- ]
- header_fmt = '{:10} ' + ' '.join(['{:^8}'] * 6)
- print header_fmt.format(' ',
- '1/8 (1)', '-1/8 (1)',
- '1/8 (2)', '-1/8 (2)',
- '1/8 (3)', '-1/8 (3)',
- )
- for rounding_mode in ROUNDING_MODES:
- print '{0:10}'.format(rounding_mode.partition('_')[-1]),
- for precision in [1, 2, 3]:
- context.prec = precision
- context.rounding = getattr(decimal, rounding_mode)
- value = decimal.Decimal(1) / decimal.Decimal(8)
- print '{0:^8}'.format(value),
- value = decimal.Decimal(-1) / decimal.Decimal(8)
- print '{0:^8}'.format(value),
- print
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement