Look at what they need to mimic a fraction inaccurately.
The fundamental mathematical nature of how binary floating point values are stored means that extremely straightforward and rational (in the mathematical sense of the term) base-10 arithmetic can surprisingly often yield results that are irrational (again, mathematically) in binary - hence why you’ll sometimes see a result of 3.000000000101325 or something like that in places where you’d expect the result to be simply 3.0
Yep. Open your browser’s console and do
.1 + .2and you get0.30000000000000004.One of the reasons not to use floating point when working with money.
What’s the right way to do money math without floats?

Eviltoasts pict-rs is being silly again
Cause fractions can be figured out in context. You can store the numerators and have the denominator as a constant in the code.
You can also have a type which does it. Raku has a Rational type for this.
Python has the Fraction type, and there are many more
Part of my first programming courses in the 90s in C were creating a native fraction type.



