How to limit BigDecimal to a fixed fractions amount?

Viewed 2154

I'm trying to create a BigDecimal class that has always a fixed maximum fractions count. But when printing that number, it is not cut to the fractions I defined in scale. Why?

class MyDecimal extends BigDecimal {
    public MyDecimal(double val) {
        super(val); 
        setScale(4, RoundingMode.HALF_UP);
    }
}


Sysout(new MyDecimal(0.0001));
//0.000100000000000000008180305391403130954586231382563710212707519531254
3 Answers
Related