+ Start a Discussion

How to format a decimal into a currency string in an apex class? (without using apex page elements)



I am currently formatting a currency manually for a class which is not intended to be displayed on a SF page, hence cannot use apex.output* objects. (It is being used in an email that is "built" in the class.)  This is not allowing me to use any of SF wizardry ... is there a method that will allow me to include a format string to convert the Decimal value that will use the current locale settings?  (Is 123456.78 displayed as 123,456.78 or 123.456,78?)   If not, then how about a format string that will allow me to indicate I want 2 decimal places?  (I can get the commas using


But it doesn't display the .00 at the end.)






Message Edited by VanyaR on 12-31-2009 05:19 AM

Sample Page....


apex:page controller="Sample" tabstyle="Property__c" sidebar="false">
<apex:pageBlockTable value="{!PropertyValues}" var="SV">

<apex:column headerValue="Name"   value="{!SV.PropertyName}" rendered="true"/>
<apex:column headerValue="Cost"   value="{!LA.PropertyCost}" rendered="true"/>
<apex:column headerValue="DisCount" value="{!LA.strDisCount}" rendered="true">





Sample Class---


public class sample
public sample()

public List<InnerClass> listSample ;
public List<Property__c> lstProperty;
public class InnerClass
//Take the String for Assinginf to double value.
public string PropertyName{get;set;}
public string  PropertyCost{get;set;}
public Integer intDisCount;

public InnerClass(string Name,double Cost,double Discount)
PropertyName = Name;
PropertyCost = '$' + Cost;
strDisCount = intDisCount;


public List<InnerClass> getPropertyValues()
lstProperty = [select Name__c,Cost__c,Discount__c from Property__c Limit 1000];
listSample = new List<InnerClass>();
for(Integer i=0;i<lstProperty.size();i++)
if(listSample.size() > 0)
return listSample;
return null;




Just See This Sample U can Understand

Raymond van AkkerenRaymond van Akkeren
Decimal amount = 0.00;
System.debug(JSON.serialize(amount));  //DEBUG|0.00