This function accepts actual price and discounted price as parameters and returns percentage value.
Function
function percentage(actual_price, discounted_price){
return Math.abs(Math.round((((discounted_price - actual_price) * 100) / actual_price)));
}
Calling The Function
alert(percentage(100, 75) + '%');
Output
25%

Leave A comment
Email address is optional and will not be published. Only add email address if you want a reply from blog author.
Please fill required fields marked with *