OFFLlNE
OFFLlNE

Reputation: 797

How to format number with hyphens in gsp?

Currently I have a sortCode 123456 and I would like this thing to be formatted into 12-34-56 in gsp file without using the controller.

Code, where the result is 12,34,56

<g:formatNumber number="${sortCode}" format="##,##" />

Any way to use replaceAll on the above code for example? Or the only way is to use the controller?

Upvotes: 0

Views: 181

Answers (1)

Mike W
Mike W

Reputation: 3932

Try the following:

${g.formatNumber( [number: "${sortCode}", format: "##,##" ] ).replaceAll( ',', '-' )}

The above will fail if sortCode is null/empty so best to protect with <g:if...

Upvotes: 1

Related Questions