Currently some of our Hibernate entities are using Doubles to store monetary amounts, the database stores this value as a numeric(10,2). The calculation of these monetary double amounts are always calculated using BigDecimals and then the entity value is set as a double.
Example:
Order order = new Order();
OrderLineItem line = new OrderLineItem(1.0, 450.00);
BigDecimal orderValue = BigDecimal.valueOf(line.getQty())
.multiply(BigDecimal.valueOf(line.getAmount()));
order.setOrderTotal(orderValue.setScale(2, ROUND_HALF_EVEN).doubleValue());
This has worked fine so far, however I'm wondering if this has any potential risks for some sort of rounding error.
Thoughts?