From 564ec839c06a80cda25e945aa2b4892c633d85a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stuardo=20Rodr=C3=ADguez?= Date: Thu, 17 Jan 2013 15:14:50 -0500 Subject: [PATCH] fixed #647 There is a JS problem when doing float sums, solved multiplying the breakdown for 100 before the sum --- www/assets/js/app.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/www/assets/js/app.js b/www/assets/js/app.js index 63429dbd9..a0806e123 100644 --- a/www/assets/js/app.js +++ b/www/assets/js/app.js @@ -1301,6 +1301,13 @@ App.cart = { return tip; }, + /** + * Sums the breakdown and returns formated number + * + * Because of the JS math problem we can't sum decimals, let's multiply it all by 100 + * + * @return string + */ total: function() { var total = 0, @@ -1311,15 +1318,21 @@ App.cart = { finalAmount = 0 ; - var breakdown = this.totalbreakdown(); + var breakdown = this.totalbreakdown() ; + // Because of the JS math problem we can't sum decimals, let's multiply it all by 100 + for (i in breakdown) { + breakdown[i] *= 100; + } total = breakdown.subtotal; feeTotal = total; feeTotal += breakdown.delivery; feeTotal += breakdown.fee; finalAmount = feeTotal + breakdown.taxes; - finalAmount += this._breakdownTip(total); + finalAmount += breakdown.tip; + finalAmount /=100; // return it to decimals + finalAmount = App.ceil(finalAmount).toFixed(2); - return App.ceil(finalAmount).toFixed(2); + return finalAmount; }, /** @@ -1341,7 +1354,6 @@ App.cart = { feeTotal += elements['fee']; elements['taxes'] = this._breackDownTaxes(feeTotal); elements['tip'] = this._breakdownTip(total); - console.log(elements); return elements; },