Search code examples
javamathbigdecimalapfloat

How to use ApfloatMath.round()?


In this snippet I expected "2" as the result?

Apfloat f = new Apfloat("1.5", 50);
f = ApfloatMath.round(f, 15, RoundingMode.HALF_UP);
System.out.println(f.toString());

Or should ApfloatMath.round() be used differently?


Solution

  • I have never heard of apfloat but one google query showed me:

    round(Apfloat x, long precision, RoundingMode roundingMode)
    

    So apparently you are rounding with a precision of 15, why do you expect 1.5 to magically become 2?

    In other words: set precision to 0 or 1 (depends on the implementation)