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
VanyaRVanyaR 

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

 

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

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
 

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