0
Hi programmers what the condition to sum the fraction number
1/2+1/3=5/6
2 Answers
+ 1
Well you if a decimal approximation is good enough you can convert the fractionsâto 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 đ¸đ¸