I’m having a problem with repeated decimals. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I’m having a problem with repeated decimals.

I managed to get a program take takes in a double and turn it to fraction. The problem with my program it’s not display the repeated decimal one. Example .3333 Output 1/3 My output 33/100 Any ideas https://code.sololearn.com/cUr47b9YZ221/?ref=app

15th Apr 2022, 11:28 PM
Yones Mussa
3 Answers
+ 2
Check 0.125, which should result in 1/8 but results in 3/25. The problem is that you have a built-in resolution in line 34 which is rather coarse. A better strategy would be to take the number as a string, split at the decimal point and treat the integral and fractional parts individually as integers.
16th Apr 2022, 5:20 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
0
Technically, it could be 333/1000 or 3333/10000 and so on. Why not those variations but the 33/100 variation instead? 1/3 is an aproximation.
16th Apr 2022, 12:36 AM
Slick
Slick - avatar
0
Slick im currently doing a project and its better doing it with lowest mixed fraction
16th Apr 2022, 12:38 AM
Yones Mussa