You need to sign in to do that
Don't have an account?
Meena25
Amount format issue decimal places 2
setScale(2) doesn't work for me. If the amount is 53, i want 53.00, if it is 53.1, i want it to show as 53.10 but currently it shows as only 53 or 53.1, it cuts off the zero.
Please see my code below;
public class BillAndPayWrapper {
@AuraEnabled public DateTime postDate;
@AuraEnabled public String billPeriod;
@AuraEnabled public Boolean showSuccess;
@AuraEnabled public String invoice;
@AuraEnabled public Decimal amount;
@AuraEnabled public String amount_formatted;
@AuraEnabled public String docType;
@AuraEnabled public String pdfDocURL;
BillAndPayWrapper(BillingHistoryServiceSet__x billPay, String companyCode) {
this.postDate = billPay.PostingDate__c;
this.invoice = billPay.InvoiceNo__c;
this.amount = billPay.TotalDueAmt__c.setScale(2);
this.billPeriod = billPay.BillPeriod__c;
this.billPeriod = this.billPeriod.right(2) + '/' + this.billPeriod.left(4);
if (amount<0) {
amount=amount*-1;
this.amount_formatted = '($' + String.valueOf(amount.format()) + ')';
showSuccess=true;
}
else this.amount_formatted = '$' + String.valueOf(amount.format());
please note: external object amount field data type is number
Please see my code below;
public class BillAndPayWrapper {
@AuraEnabled public DateTime postDate;
@AuraEnabled public String billPeriod;
@AuraEnabled public Boolean showSuccess;
@AuraEnabled public String invoice;
@AuraEnabled public Decimal amount;
@AuraEnabled public String amount_formatted;
@AuraEnabled public String docType;
@AuraEnabled public String pdfDocURL;
BillAndPayWrapper(BillingHistoryServiceSet__x billPay, String companyCode) {
this.postDate = billPay.PostingDate__c;
this.invoice = billPay.InvoiceNo__c;
this.amount = billPay.TotalDueAmt__c.setScale(2);
this.billPeriod = billPay.BillPeriod__c;
this.billPeriod = this.billPeriod.right(2) + '/' + this.billPeriod.left(4);
if (amount<0) {
amount=amount*-1;
this.amount_formatted = '($' + String.valueOf(amount.format()) + ')';
showSuccess=true;
}
else this.amount_formatted = '$' + String.valueOf(amount.format());
please note: external object amount field data type is number
If so, why don't you use the <lightning:formattedNumber> tag to display the currency correctly? Reference (https://developer.salesforce.com/docs/component-library/bundle/lightning:formattedNumber/example#lightningcomponentdemo:exampleCurrencyFormatting)
Documentation link (https://developer.salesforce.com/docs/component-library/bundle/lightning-formatted-number/example):
Now.. as for how should you display it.. Even if you want to display it just as a decimal number but no currency sign, you can still use the formattednumber tag. The documentaiton in the links should show you how to do it. You should also be able to display the negative ($0.00) on the client side with an aura:if (if using aura components) or <template if:True (for LWC).
For example:
GGmedia cung cấp dịch vụ SEO (https://ggmedia.biz/)
Use this code to create an input field that will show double decimal places.
'step' is used to define how many decimal places you want to show.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com