# ${25/5} output 5.0 why not 5?

Joshua Antony

Ranch Hand

Posts: 254

posted 9 years ago

Because the following rules are applied for the division :

For the multiplication, both values will be coerced to Long.

So you'll get something similar to :

� IfAorBisaBigDecimal or a BigInteger, coerce both to BigDecimal and return

A.divide( B, BigDecimal.ROUND_HALF_UP ).

� Otherwise, coerce both A and B to Double and apply operator

� IfAorBisaBigDecimal or a BigInteger, coerce both to BigDecimal and return

A.divide( B, BigDecimal.ROUND_HALF_UP ).

� Otherwise, coerce both A and B to Double and apply operator

For the multiplication, both values will be coerced to Long.

So you'll get something similar to :

[My Blog]
*All roads lead to JavaRanch*