cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Convertion in c++
Convertion in c++
Jul 7, 2012 at 5:23pm UTC
shaishab
(2)
How can I convert floating point to fraction value in c++ ?
ie.input is 1.5 output is 3/2.
please help me.
Jul 7, 2012 at 5:30pm UTC
Moschops
(7244)
How would you do it on paper? Like that.
Jul 7, 2012 at 5:57pm UTC
shaishab
(2)
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 !
Jul 7, 2012 at 7:08pm UTC
Moschops
(7244)
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
Jul 7, 2012 at 7:08pm UTC
Jul 7, 2012 at 11:41pm UTC
ne555
(10692)
until you reach an integer.
You know that that wouldn't work with the computer
Jul 8, 2012 at 12:02am UTC
Moschops
(7244)
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.