0
Hi programmers what the condition to sum the fraction number
1/2+1/3=5/6
2 Réponses
+ 1
Well you if a decimal approximation is good enough you can convert the fractionsto floating point numbers first. Then add them.
If you need the fraction answer you can convert back by multiplying by different numbers until you get an integer. You allow for a tolerance like 1% or 0.01% etc. This because Floating point is an approximation, and recurring decimals don't always multiply up correctly.
If you want an easy error resistant to add fractions, then you can make your own data type, probably implemented as a class.
Or you could see if there is a library available to do this already. I suggest boost rational:
http://www.boost.org/doc/libs/1_65_1/libs/rational/index.html
0
thank you jared 🌸🌸