How to format Number to Currency with Criteria (JPA 2.0 EclipseLink)

442 Views Asked by At

Is there a way to format this:

CriteriaQuery<Country> q = cb.createQuery(Country.class);
  Root<Country> c = q.from(Country.class);
  q.select(c.get("currency")).distinct(true);

So when all the NUMERIC currency elements are returned they look like:

12345 -> $12,345.00

123,45 -> $123.45

This way I don't hace to loop the resultset formating strings.

1

There are 1 best solutions below

0
On

Here's the answer:

https://stackoverflow.com/a/40008789/2545722

Just needed to use the CriteriaBuilder's function method, which allows developers to call SQL functions. I don't like it because this code should change if the DB is changed.