// 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) 
import java.math.BigDecimal;
import java.math.RoundingMode;

public class M3 {
    public static void dump(BigDecimal a, String op, BigDecimal b, BigDecimal res) {
        System.out.printf("%s (%d) %s %s (%d) = %s (%d)\n",  a, a.scale(), op, b, b.scale(), res, res.scale());
        System.out.printf("as integer: %d rounded half up %d rounded down %d rounded floor\n", res.setScale(0, RoundingMode.HALF_UP).intValue(),
                                                                                               res.setScale(0, RoundingMode.DOWN).intValue(),
                                                                                               res.setScale(0, RoundingMode.FLOOR).intValue());
    }
    public static void main(String[] args) {
        BigDecimal a = new BigDecimal("4.2");
        BigDecimal d = new BigDecimal("2.1");
        BigDecimal e = new BigDecimal("6.2");
        BigDecimal f = new BigDecimal("3.1");
        BigDecimal g = new BigDecimal("-4.2");
        BigDecimal res;
        res = d.divide(a);
        dump(d, "/", a, res);
        res = f.divide(e);
        dump(f, "/", e, res);
        res = d.divide(g);
        dump(d, "/", g, res);
    }
}
