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

1
  • 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. Commented Nov 2, 2011 at 17:18

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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);
    }

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.