How do I round off a money amount to two decimals using the arithmetic convention that
167,7451 is rounded to 167,75
12,1819784 is rounded to 12,18
Notice I want to do it arithmetically and be returned a float and not a string so simple formatting solutions are not what I'm searching for.
So far I found the following:
amount = 167.7451;
rounded = (amount.toFixed(2));
alert(rounded);
however the result of toFixed() is a string, so if I need to do more calculations I need to parse the string to a float again.
The .toPrecision method instead wants to know how many digits I need so to round the amount to two decimals I'd need:
amount = 167.7451;
alert(amount.toPrecision(5));
that's ridiculous because I'd need to first know how many digits I have before the decimals.
Updated code should work.