Hi all I got a very stupid question which I could not figure out how to solve it.
So basically I am trying to calculate how many percentage of increment/decrement for the expense and income of current from past month.
So let's say I got these data:
Current Month Expense: 10454
Current Month Income: 2233
Last Month Expense: 15
Last Month Income: 1500
To calculate the income:
if(thisMonthtotalIncome < lastMonthtotalIncome){
incomePercentage = Math.round(thisMonthtotalIncome/lastMonthtotalIncome * 100);
}else if(thisMonthtotalIncome > lastMonthtotalIncome){
incomePercentage = Math.round((thisMonthtotalIncome/lastMonthtotalIncome));
}
To calculate the expense:
if(thisMonthtotalExpense < lastMonthtotalExpense){
expensePercentage = Math.round(thisMonthtotalExpense/lastMonthtotalExpense * 100);
}else if(thisMonthtotalExpense > lastMonthtotalExpense){
expensePercentage = Math.round((thisMonthtotalExpense/lastMonthtotalExpense));
}
I realized the percentage was somewhat wrong because from the data above, I get the expense increases by 697%. Is there any way or correct way to limit it to be in the range of 0% - 100%?
Also, I think that the formula is wrong as well cause I am so lousy at Maths.
Any suggestions? Thanks in advance!