I am trying to calculate percentage fees for dollar amount. I have tried many ways but the rounding seems off. Is there a standard or best practice for calculating fees?
fee = 2.25 // %
total = 2
sFee = parseFloat(((fee / 100) * total).toFixed(2));
console.log(sFee)
// sFee is $0.04, should be $0.05
fee = 2.25 // %
total = 10
const x = (fee / 100) * total;
pFee = Math.round(x * 100) / 100;
console.log(pFee)
// this works with most numbers but when total is 10
// pFee is $0.22, should be $0.23
fee = 2.25 // %
total = 2
sFee = parseFloat(((fee / 100) * total + 0.00000000001).toFixed(2));
console.log(sFee)
// sFee is $0.05,
// this seems to work best, not sure if it is the best solution.