You need to sign in to do that
Don't have an account?

How to format a decimal into a currency string in an apex class? (without using apex page elements)
All,
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
DecValue.format();
But it doesn't display the .00 at the end.)
Thanks,
Vanya
Sample Page....
apex:page controller="Sample" tabstyle="Property__c" sidebar="false">
<apex:form>
<apex:pageblock>
<apex:pageBlockTable value="{!PropertyValues}" var="SV">
<columns>
<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">
</columns>
<apex:pageBlockTable
</apex:pageblock>
</apex:form>
</apex:page>
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++)
{
listSample.add(lstProperty[i].Name__c,lstProperty[i].Cost__c,lstProperty[i].Discount__c);
}
if(listSample.size() > 0)
return listSample;
else
return null;
}
}
Just See This Sample U can Understand
System.debug(JSON.serialize(amount)); //DEBUG|0.00