var current = 12000;
var june = 14600;
var may = 11200;
I want percent change with respect to 'current' month parameter. The output should be in percent and it can add or subtract w.r.t. the current month. How to do this?
One of them is the percent sign: % . It has a special meaning in JavaScript: it's the remainder operator. It obtains the remainder between two numbers. This is different from languages like Java, where % is the modulo operator.
Note that if one of your values is 0 you will get either -100% or Infinity%. This solves that problem:
function percIncrease(a, b) {
let percent;
if(b !== 0) {
if(a !== 0) {
percent = (b - a) / a * 100;
} else {
percent = b * 100;
}
} else {
percent = - a * 100;
}
return Math.floor(percent);
}
Its simple maths:
var res=(current-june)/current*100.0;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With