# Collection of code snippets by Arne Vajhøj 
# (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
from decimal import *

def get_scale(d):
    return -d.as_tuple().exponent

def dump(a, op, b, res):
    print('%s (%d) %s %s (%d)= %s (%d)' % (a, get_scale(a), op, b, get_scale(b), res, get_scale(res)))
    print('as integer: %d rounded half up %d rounded down %d rounded floor' % (res.to_integral_value(ROUND_HALF_UP),
                                                                               res.to_integral_value(ROUND_DOWN),
                                                                               res.to_integral_value(ROUND_FLOOR)))

a = Decimal('4.2')
d = Decimal('2.1')
e = Decimal('6.2')
f = Decimal('3.1')
g = Decimal('-4.2')
res = d / a
dump(d, '/', a, res)
res = f / e
dump(f, '/', e, res)
res = d / g
dump(d, '/', g, res)
