Showing posts with label BigDecimal. Show all posts
Showing posts with label BigDecimal. Show all posts

Monday, May 9, 2011

Best data type for PRICE!

In attempting to persist U.S. currency formatted values from an H2 database via Hibernate and JPA, I've found using a primitive type of double, a variable precision and a scale of 2 finally gave me what I wanted.

BigDecimal result = new BigDecimal(129.99, 7).setScale(2);

BigDecimal(double value, int precision)