I am getting derefrence null object error when i call method in vf page
Controller:
public With Sharing class Invoice {
public decimal a {get;set;}
public Invoice_Master__c invo {get;set;}
List<Invoice_Master__c> listIn {get;set;}
public Invoice(ApexPages.StandardController Controller){
listIn=[Select id,Name,(Select id,Name From Invoice_Line_Items__r) From Invoice_Master__c];
/* decimal a = invo.Total_Amount__c;
system.debug('Currency is ' + (a.format().contains('.')?a.format():(a.format()+'.00'))); */
}
public string getamount(){
List<String> args = new String[]{'0','number','###,###,##0.00'};
String s = String.format(this.invo.Total_Amount__c.format(), args);
System.debug(s);
return s;
}
}
VF page:
<td>
<b><apex:outputText value="{!amount}">
<apex:param value="{!Invoice_Master__c.Total_Amount__c}"/>
</apex:outputText></b>
</td>
How to call decimal to currency format in controller into vf page?
You may change code as below: public String getAmt() {
String sAmt = '', sTemp ='', sLast='';
Decimal dAmt = Opp.Amount;
sAmt = FormulateAmountInString(dAmt);
return sAmt;
}
public string FormulateAmountInString(Decimal dAmt) {
String sAmt = '', sTemp ='', sLast='';
If(dAmt > 1000) {
sAmt = String.valueOf(dAmt);
sLast = sAmt.right(6);
sTemp = sAmt.left(sAmt.length() - 6);
if(sTemp.length() > 2) {
while( sTemp.length()/2 > 0) {
sLast = sTemp.right(2)+ ',' + sLast;
sTemp = sTemp.Left(sTemp.length() -2);
}
}
sAmt = sTemp + ',' + sLast;
//sAmt = sAmt + '.' + String.valueOf(dAmt).substringAfter('.');
} else {
sAmt = String.valueOf(dAmt);
}
return sAmt;
}