function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kent ManningKent Manning 

How to formate currency in Visualforce with a wrapper class.

We have a quote template (a visual force page that renders as a PDF). This page currently uses the MessageFormat class from Java to format the currency fields on the quote. 

 

Here is the Visualforce example of how the Unit price on a product line item is formatted:

 

     <apex:column headerValue="Unit Price">

             <apex:outputText value="{0, number, $###,###,##0.00}">

                    <apex:param value="{!item.ListPrice}"/>

             </apex:outputText>

     </apex:column>

 

Note that <apex:outputText value="{0, number, $###,###,##0.00}"> gives back a USA currency format of $1,000.00. However, I need to have this be €###.###.##0,00 where the value comes out as €1.000,00. Note the position of the comma and period in the string.  It has been determined that the Java MessageFormat class will not work with other locations outside of the US. So I need another solution.

 

I have found some code in the Force.com Cookbook that will work to convert the decimal string into a Euro format:

 

     Decimal Amount = 199850010.28;
     Decimal dollars;
     Decimal cents;
     dollars = Amount.intValue();
     system.debug('Dollars is set to:' + dollars);
     cents = Amount - dollars;

     cents = cents.setScale(2);
     system.debug('cents is set to:' + cents);
     String AmtText = dollars.format()+','+ cents.toPlainString().substring(2) + ‘€’ ;
     System.debug(AmtText);

 

     199.850.010,28 €

 

 

I need help converting this code into a method inside of my Visualforce page controller. Also, I don’t know how link the output of this method to the appropriate line item values on the quote page.  It has been suggested by Salesforce Support that a wrapper class would do the dirty work. However, I have no experience with how to make a wrapper class work, nor how to use the above code within the wrapper class to format all of the currency fields (List Price, Discount Price, Discount Amount, Subtotal Amount, etc.) on our quote. 

 

Does anyone have a custom code example, or techniques for formatting currency in a Visualforce page so that Euros display properly?  I’m sure someone, somewhere has run into this requirement before since Salesforce is an international company.  Please share how you resolved this issue when using a Visualforce page template.

hemantgarghemantgarg

For proper formatting you can use <apex:inputField ... /> directly. It shows currency fields in proper format.

Kent ManningKent Manning

Thanks Hemant.  I've tried the <apex:outputField/> tag but this doesn't work because we are using dated exchange rates in our org.  When I try to use this I get an error message and I can't save the visualforce page. 

 

The thing that puzzles me the most is why hasn't Salesforce designed a way, via visualforce, for formatting currencies?  They are an international company and I'm sure they have run into this issue.  In fact there are issues on the idea exchange about this very thing!