I have multiple currency/percent fields on which I need a method to add Zeros at the end. for example I have a currency(18,2) with value 4590, should end as 4590.00. percent(3,3) with value 3.3 should be 3.300. I need a reusable method which does this. Any help is much appreciated.Thanks!

  • Where are you wanting to do this? In Visualforce page?
    – Eric
    Commented Nov 4, 2015 at 1:08
  • @Eric : In apex for string concatenation
    – cartman
    Commented Nov 4, 2015 at 1:10

1 Answer 1


If you are talking about displaying it on a VF page you can use one of these:

<apex:outPutText value="{0,number,currency}">
   <apex:param value="{!YOURFIELD}"/>

or to control decimal places:

<apex:outPutText value="{0,number,$#,###.000}">
   <apex:param value="{!YOURFIELD}"/>


for a string in apex simply do this:

public static string formatInteger(Integer i, integer places){
   if(i == null) return '';
   return formatDecimal(decimal.valueOf(i));

public static string formatDecimal(Decimal d, Integer places){

   if(d == null || places == null) return '';

   return string.valueOf(d);


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .