Alex Rivera | Logout

Hibernate - BigDecimal Mapping Precision

Asked 2011-10-13T14:09:43.357
8

Problem: Seems my mapping class for a big decimal is dropping 0 when grabbing values like 50.20 from the oracle database. It will grab the value correctly if its 50.23 but nothing with a 0 on the end. I imagine its something simple i am missing. Suggestions? Thanks in advance.

Details

Database: Oracle 11G Field Definition: Numeric(8,2)

mapping getter/setter

    @Column ( name="PRICE", precision = 8, scale = 2 )
private BigDecimal price;

public BigDecimal getPrice()
{
    return price;
}
public void setPrice( BigDecimal price )
{
    this.price = price;
}
Edit
Report

1 Answer

8

50.2 is the same as 50.20, 50.200, etc. If you want to display it with two digits use java.text.DecimalFormat.format(..)

Specifying precision limits the maximum number of decimal digits, not the minimum.

answered 2011-10-13T14:23:06.913

Your Answer