javascript - JQuery Calculation drops cents -
i have block, pulls current amount paid on item firebase , amount being paid @ moment. supposed add 2 make third variable.
for reason code drops cents off total.
singleref.once("value", function(snapshot) { var = parseint(snapshot.val().amounts.paid); // amount paid var b = parseint(invoice.payment.amount); // amount being applied var c = + b; console.log(c); });
let's following happening:
a = 0; b = 10.86;
the result in code be:
c = 10; // should 10.86
let's following happening:
a = 10.00; b = 10.86;
the result in code be:
c = 20; // should 20.86
it doesn't matter cents are, rounds rid of them. i've tried adding .tofixed('2')
of variables, , b, , c. result in same no cent totals.
how!? i've been trying past few hours, it's simple can't figure out. it's driving me nuts! i'm using angularjs , firebase.
the function parseint()
specifically parsing integers so, if give 3.14159
, give 3
.
if want parse floating point value, try parsefloat()
.
for example, following code:
var = parseint("3.141592653589"); var b = parseint("2.718281828459"); var c = + b; alert(c); var d = parsefloat("3.141592653589"); var e = parsefloat("2.718281828459"); var f = d + e; alert(f);
will give 2 different outputs:
5 5.859874482047999
Comments
Post a Comment