Reputation: 263
Hi I'm trying to calculate values with standard way like 12,000.00
or 1,678,900.00
or 0.36
values but its not calculating my values if comma or point exists. here is my code jsFiddle
for example
I'm giving the values
Payment Sent 1: 12,000.00
Payment Sent 2: 1,678,900.00
Payment Sent 3: 0.36
Now Total Payment Sent convert into 0.00
values
Total Payment Sent: 0.00
So how to calculate these values properly.
Upvotes: 1
Views: 52
Reputation: 6527
function paymentSentSum() {
var totalPaymentSent = 0;
var that;
$(".paymentSentSum").each(function() {
that = parseFloat(this.value.replace(/\,/g,''));
if(!isNaN(that) && that != 0) {
totalPaymentSent += that;
}
});
$("#paymentSentTotalPaymentSent").val((totalPaymentSent).formatMoney(2, '.', ','));
}
function addTrailingZerosBookings() {
var that;
$(".paymentSentSum").each(function() {
that = parseFloat(this.value.replace(/\,/g,''));
if(that && !isNaN(that)) {
//$("#" + $(this).attr('id')).val(trailingZeros(this.value));
if(isAlphaNumeric(that)) {
$("#" + $(this).attr('id')).val(that.formatMoney(2, '.', ','));
} else {
$("#" + $(this).attr('id')).val(this.value);
}
}
});
}
Here use this. I have used parseFloat initially when to get the amount and then applied your checks. Rest all is good.
Code Pen : http://codepen.io/anon/pen/JdqLgB
Upvotes: 3