I'm trying to get the percentage between two numbers for the purpose of showing the difference as far as a discount. I've tried to simplify it as much as I can but I still cant get what I want.
Here is an example.
var RegPrice = 8.95;
var OnSale = 6.67;
var OnSaleAT = Math.abs(Math.max(100.00 - OnSale / RegPrice * 100.00));
alert(OnSaleAT.toFixed(2));
What I'm trying to get is the alert(); to return a value of 25.50. However, I'm getting 25.47.
Any ideas on how I can get this right?
25.47%is correct. - Rob W6.67 / 8.95 = 0.74525,100 - 74.525 = 25.475, fix at 2 decimal points is25.47. If you want to round, you'll need to useMath.round(). - zzzzBov