2

I would like to display the Purchase price with thousands separator : for example

16.00
24.96
3,316.57

the problem when I write this code :

<apex:outputText value="{0,number, 0,000.00}">
                    <apex:param value="{!opp.Purchase_Price__c}"/>
                    </apex:outputText>

the result is like this

0,016.00
0,024.96
3,316.57

the last value is right , I would like to remove 0,0 on

0,016.00

When I change the code like this :

 <apex:outputText value="{0,number, 000,000.00}">
                    <apex:param value="{!opp.Purchase_Price__c}"/>
                    </apex:outputText>

related to the discussion here : currency formatting

the result is like this :

000,016.00 instead of 16.00
003,316.57 instead of 3,316.57

do you have an idea ?

  • 1
    Try ###,##0.00 – cropredy Jul 14 '15 at 17:16
2

I'll be the first to say that the examples in the Java MessageFormat doc can be cryptic and not comprehensive (and it doesn't help that the link in the VF doc is broken (points at an older Java version doc page, no longer maintained by Oracle)

The relevant Java doc with rules for decimal numbers is here

If you use # then if there is a digit in that place, the digit is displayed, else it is suppressed. Whereas if you use 0, the digit is displayed if present for the place, otherwise, 0 is printed

So..

###,###.00 will display 1,234.00 as 1,234.00, not 001,234.00

###,###.## will display 23.90 as 23.9 ###,###.00 will display 23.90 as 23.90

More examples can be found here

  • >> Hi , thank you for your response , my last question how to do if we would like to separate thousand by space instead of comma " , " . – Julio Ludovic Ramihone Jul 16 '15 at 9:20
  • Hmm ... per the Java doc: the comma is the separator character when used in non-localized patterns, otherwise the locale-specific separator is used from Java class DecimalFormatSymbols - I don't know how SFDC VF manages that. You could do the work in the controller instead – cropredy Jul 16 '15 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.