tags:

views:

15

answers:

1

Is it somehow possible to only display the fraction digits with fmt:formatNumber? I basically need to render a price-like double in two fields: decimal and fraction digits (123.456 -> 123 456) and I want to avoid string splitting etc. :-)

The solution has also to work with a minimum number of fraction digits in order to create for instance this:

123.1 -> 123 01

The data represented is a price that is stored as a decimal number for some reason.

minFractionDigits="2" would produce .01 as output for the second field.

Another output example would be:

123<span>01</span>
+1  A: 

Yes:

<fmt:formatNumber maxIntegerDigits="0" />

Update:

How about multiplying by 100, 1000 or something like that, and outputting it as integer digits. Say:

<fmt:formatNumber maxIntegerDigits="3"  value="${yourValue * 1000}" 
     maxFractionDigits="0" />

Thus you will have to trim some decimal digits, though.

Bozho
Yes, this works for the basic case but sadly not in combination with minFractionDigits. The moment this is added, the output also contains the comma. Sorry, forgot to mention that in the question. Will update it in a second.
Horst Gutmann
@Horst Gutmann see updated
Bozho
Nice idea, thanks :-)
Horst Gutmann