12

I would like to display the amount in $12,050,999.00 format.

I tried as follows:

<h:outputText value="#{sampleBean.Amount}">
    <f:convertNumber pattern="###,###" currencySymbol="$" type="currency"/>
</h:outputText>

However, it didn't display the amount in the desired format. I got 12,050,999 instead.

The desired format is shown in the below image:

enter image description here

How can I achieve this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
09Q71AO534
  • 4,300
  • 13
  • 44
  • 68

1 Answers1

28

Your pattern is wrong for a currency. You should be using pattern="¤#,##0.00".

<f:convertNumber pattern="¤#,##0.00" currencySymbol="$" />

However, there's more at matter: in your original code you also specified the type attribute, which is correct, but this is mutually exclusive with the pattern attribute whereby the pattern attribute gets precedence.

You should actually be omitting the pattern attribute and stick to the type attribute.

<f:convertNumber type="currency" currencySymbol="$" />

Note that this uses the locale as available by UIViewRoot#getLocale() which is expected to be an English/US based locale in order to get the right final format for the USD currency. You'd like to explicitly specify it in either the <f:view>:

<f:view locale="en_US">

or in the locale attribute of the <f:convertNumber>:

<f:convertNumber type="currency" currencySymbol="$" locale="en_US" />

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 1
    I am trying the same with InputText " " but i am not able to solve the [issue with paste](http://forum.primefaces.org/viewtopic.php?f=14&t=35104) – 09Q71AO534 Nov 05 '14 at 15:12
  • [Added a Question](http://stackoverflow.com/questions/26760853/unable-to-paste-the-content-in-primefaces-extension-peinputnumber-using-mouse) – 09Q71AO534 Nov 05 '14 at 15:28