Convertion in c++

How can I convert floating point to fraction value in c++ ?
ie.input is 1.5 output is 3/2.
please help me.
How would you do it on paper? Like that.
thanks !
one process is 1.5*10/10=15/10=3/2
one digit (5) after floating point so multiply that value by 10 and divided by 10 . but if more digit after floating point how can convert easily ?
ie. input 1.714285714 then output 12/7 .
thanks !
But 1.71428571 does not equal 12/7.

Anyway, let's take 0.0000015 - you can keep multiplying by ten until you reach an integer.

0.0000015 = 15/10000000 = 3/2000000

Last edited on
until you reach an integer.
You know that that wouldn't work with the computer
until you reach an integer Until you reach something close enough to an integer that you're happy with it.
Topic archived. No new replies allowed.