Search code examples
playframeworkbigdecimal

Losing precision by saving a BigDecimal in Play Framework


I'm using Play Framework 1.2.4 with H2 in memory database.

public void aBigDecimalSavingTest() {
    BigDecimalEntity bde = new BigDecimalEntity();
    bde.bd= new BigDecimal("0.225");
    System.out.println(bde.bd); // print 0.225
    bde.save();

    bde = BigDecimalEntity.findById(Long.valueOf("1"));
    System.out.println(bde.bd); // print 0.23
}

Where does this problem come from ? Play Framework ? Database support ? JPA Missing Annotation ? ...

Thanks!


Solution

  • You might need to specify the precision on your Entity:

    @Column(precision = 16, scale = 4)
    BigDecimal bigdec;