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
Arun BalaArun Bala 

Thousand's separator ..

Folks,

I have a decimal which I need to display with thousands separator on a visualforce page. An outputText displays that value.

 

E.g: now it is 5360. I wanted it to be displayed as : 5,360

 

Any suggestions or ideas on how can I convert the decimal to the currency format ?? unforunately, I cannot use the exact sObject field as I am using a wrapper class.

 

 

Thanks folks.

Best Answer chosen by Admin (Salesforce Developers) 
dchasmandchasman

Even when you are using a wrapper class you can still leverage a proxy instance of an sobject (any sobject type that has a currency field will work - although you might need to use a custom field for this to get the formating you want) in your wrapper class that you push the value you want to display using an apex:outputField into. For example (you'll have to adapt this to your wrapper class of course):

 

 

<apex:page controller="CurrencyProxyDemoController"> <apex:outputField value="{!proxy.annualRevenue}"/> </apex:page> public class CurrencyProxyDemoController { public Account getProxy() { proxy.annualRevenue = 123456.78; return proxy; } private final Account proxy = new Account(); }

 

 

 

All Answers

Arun BalaArun Bala
Folks any hints ? This is lil urgent for me, sorry :-(
David VPDavid VP

Try this :

 

 

<apex:page controller="testdecimalController"> <apex:outputText value="{!testdecimalformatted}"></apex:outputText> </apex:page> public class testdecimalController { public Decimal testdecimal {get;set;} public testdecimalController() { this.testdecimal = 10000000000.00; } //getter method for a formatted version for display public String getTestdecimalformatted() { return testdecimal.format(); } }

 

 -david-

 

Arun BalaArun Bala
Thanks for the quick response David. This works for the comma, the new issue is I lose the decimal if I use .format()
Arun BalaArun Bala
Folks - do anyone know any other approach for this issue ? Thanks.
dchasmandchasman

Even when you are using a wrapper class you can still leverage a proxy instance of an sobject (any sobject type that has a currency field will work - although you might need to use a custom field for this to get the formating you want) in your wrapper class that you push the value you want to display using an apex:outputField into. For example (you'll have to adapt this to your wrapper class of course):

 

 

<apex:page controller="CurrencyProxyDemoController"> <apex:outputField value="{!proxy.annualRevenue}"/> </apex:page> public class CurrencyProxyDemoController { public Account getProxy() { proxy.annualRevenue = 123456.78; return proxy; } private final Account proxy = new Account(); }

 

 

 

This was selected as the best answer
Arun BalaArun Bala

Thanks for your response Doug. Yes I think I would need to have a custom field to define my own formatting.

 

 

Thanks again.