tags:

views:

28

answers:

1

How does the Grails tag fieldValue perform its formatting?

I have an domain class with an Double attribute.

class Thing {
    Double numericValue
}

In GSP, the fieldValue is used (as created by grails generate-all) for rendering:

${fieldValue(bean:thing, field:"numericValue")}

Unfortunately digits after 3 decimal places are not displayed (ie, 0.123456 is displayed as 0.123). How do I control fieldValue's formatting?

Note that I could just use ${thing.numericValue} (which does no formatting) or <g:formatNumber>, but I'd rather use the fieldValue tag and specify the formatting. I just don't know where to specify fieldValue's formatting.

A: 

Use <g:formatNumber number="${thing.numericValue}" format="\\$###,##0.00" /> instead or use ${g.formatNumber(number:thing.numericValue, format:'\\$###,##0.00'}

Hope this helps.

Scott Warren