Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate - BigDecimal Mapping Precision

Tags:

java

hibernate

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;
}
like image 890
haju Avatar asked Oct 13 '11 14:10

haju


1 Answers

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.

like image 128
Bozho Avatar answered Oct 19 '22 08:10

Bozho