Files
classroomio/apps/dashboard/src/lib/utils/functions/number.ts
T

11 lines
292 B
TypeScript
Raw Normal View History

export function calcPercentageWithRounding(a: number, b: number) {
if (b === 0) {
return 0;
}
const rawPercentage = (a / b) * 100;
const fixedString = rawPercentage.toFixed(1);
const roundedNumber = parseFloat(fixedString);
return isNaN(roundedNumber) ? 0 : roundedNumber;
}