I wrote a function that rounded my number's decimal part into the nearest quarter(.00 | .25 | .50 | .75).
but the function for some reason sent me back string type instead of number type. why is that?
const roundToQuarter = (num) => {
let toFixed = num.slice(-2); // Num is a number with 2 decimal digits
toFixed %= 25;
if (toFixed <= 12) {
return num - toFixed / 100;
}
return num + (25 - toFixed) / 100;
};