How to calculate percentage and have up to two digits after the dot? Based on previous topic, I tried the following:
function calc(part, whole) {
if (!whole)
return 0.00;
return parseFloat((100 * part/whole).toFixed(2));
}
But what I get:
console.log((100 * 11154/48291).toFixed(2)) // 23.10
console.log((100 * 11154/48291)) // 23.09747157855501
I want the final result to be 23.09
and not 23.10
. Also I want to return a number and not a string. the toFixed()
method rounds up and returns a string. How should I do it? Maybe lodash can help me somehow?