this.total = this.total * (1 - (this.coupon.discount/100));
Jan 14, 2016
53
Level 51
Sum for subtracting a percentage with Vue
Hi all,
I have the following VueJS
this.$http.get('/coupons/' + this.coupon.code)
.success(function(coupon, finalTotal) {
this.coupon = coupon;
this.valid = true;
this.coupon.description = 'Great! You entered a valid coupon.';
this.total = this.total - this.coupon.discount; // This line
this.$set('finalTotal', this.total);
})
.error(function() {
this.coupon.code = '';
this.coupon.description = 'Sorry, that coupon does not exist.';
});
}
Where I have marked // This line I wish to know (not been that good at math) how I can make the amount coming from the database i.e 10 be a percentage and take that percentage away from the total.
How can I do this, sorry if it's a dumb ass question, but math not my strongest point!
Level 104
Just spotted an error in the calculation:
this.discountPercentage = this.coupon.discount/100;
this.discountAmount = this.total*(this.discountPercentage); // do not divide by 100 here (its already a percentage)
this.discountedTotal = this.total - this.discountAmount;
this.total = Math.round(this.discountedTotal * 100);
this.$set('finalTotal', this.total);
If you multiply a GBP£ by 100, that's the number of pennies you have - Stripe needs to make the charge in pennies
1 like
Please or to participate in this conversation.