by rcfox · 3y ago · 0 comments
No one wouldn't. Maybe your domain has very specific, unorthodox rounding requirements? The most common rounding algorithms only look at the (n+1)th digit when rounding to n decimal places.
ie: 1.4349999999999998 rounded to 2 decimal places considers only 1.434. 4 is less than 5, so the result is correctly 1.43.
Edit: I just realized I missed the forest for the trees. The original calculation should have resolved to 1.435, which would round to 1.44.
I don't think your solution would work in the general case for floating point numbers, where numbers could be much smaller than your rounding attempts. Maybe if you based it on `value * Number.EPSILON`, or something?