by mikeash · 9y ago · 0 comments
If you wanted your fees to round up then the actual code would look something like:
fee = round_up_multiply(amount, 1, 300)This isn't a fixed point number system, because you are now using a non-fixed point number representation (e.g. two numbers; which can't be represented in fix point because of their repeating nature) to represent your fraction. Trying to get all of that behavior right is more error prone than just using an arbitrary precision library in the first place.
But the other commenter was discussing arbitrary precision arithmetic libraries, not fixed-point decimals.
And an array of single precision floats is a zero-terminated UTF-8 encoded string. Using an actual fixed point decimal number type is still preferable over going straight to the underlying integer, even if it is only for the easier to read source code with decimal points where they belong instead of having to perform the transformation in your head while reading.
But the other commenter was discussing arbitrary precision arithmetic libraries, not fixed-point decimals.
Fair point.
If your language of choice has a good fixed-point decimal library, or you can switch to one that does, then I agree that would definitely be the superior solution.