0

I have a Money field in Sql server Table and mapping to double in hibernate. how to format as 999,999?(three to three separate)

for example: 45000.0 ---> 45,000

or123456
  • 2,091
  • 8
  • 28
  • 50
  • 1
    Database and hibernate keep data, not format it. The view part of your application should answer for formatting data selected with hibernate from database. – svaor Nov 02 '11 at 17:18

2 Answers2

4

I would suggest not to do this at the SQL or hibernate layer. You should handle this in you UI layer. You can use Java's DecimalFormat or see here for an example.

Community
  • 1
  • 1
legendofawesomeness
  • 2,901
  • 2
  • 19
  • 32
0
public class MyClass {
    BigDecimal money;
    public static final NumberFormat NUMBER_FORMAT = new DecimalFormat(",###");

    @Column
    public BigDecimal getMoney() {
        return money;
    }

    @Transient
    public String displayMoney(){
       return NUMBER_FORMAT.format(money);
    }

}
zmf
  • 9,095
  • 2
  • 26
  • 28