Akshay

Akshay

  • 1.5k
  • 96
  • 29.8k

Decimal addition is not working in angular

Jun 3 2022 1:14 PM
temp: number = 0;

itemToPayment = {
    "NetPayable": 0,
    "PaidAmount": 0
}

this.itemToPayment.NetPayable  = 2428.2
this.itemToPayment.PaidAmount = 1928.2
document.getElementById('lblPaid')["textContent"] = 0
document.getElementById("lblAdvanceConsume")["textContent"] = 500
badDebts = 0

hii all i'm trying to do following arithmatic with given above data

this.temp = (+this.itemToPayment.NetPayable - +this.itemToPayment.PaidAmount
            - +document.getElementById('lblPaid')["textContent"]
            - +document.getElementById("lblAdvanceConsume")["textContent"] - badDebts);

the output of the above arithmatic equation is = -2.2737367544323206e-13

expected output is zero.(2428.2  - 1928.2  - 0 - 500  -  0 ) = 0

when above input values are integer not floot then the output comes correct.

Thank you .


Answers (1)