mehmet cinar
mehmet cinar

Reputation: 160

How to use <f:convertNumber> to convert 103.99 to .99

I'm trying to get the 2-digit fraction part only using <f:convertNumber>. E.g. 103.99 must result in .99.

<h:outputText value="#{myBean.totalFare}">
    <f:convertNumber pattern="#,##0.00" />
</h:outputText>

This does not work. I also tried to use the patterns ,##.00 and ,##, but failed.

How can I achieve this?

Upvotes: 1

Views: 686

Answers (1)

BalusC
BalusC

Reputation: 1108722

That's not possible with <f:convertNumber>. It's not intented to manipulate numbers (read: performing any math on it), but it's intented to format/convert it.

You should first trim off the integer part by a modulus of 1.

<h:outputText value="#{myBean.totalFare % 1}">

Then you can use the pattern of .## in order to show two fractions only:

<h:outputText value="#{myBean.totalFare % 1}">
    <f:convertNumber pattern=".##" />
</h:outputText>

Upvotes: 2

Related Questions