• thanh Tâm
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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