Convert decimal number to rational: Difference between revisions
Content added Content deleted
Line 1,595: | Line 1,595: | ||
909//1000 |
909//1000 |
||
10//11 |
10//11 |
||
</pre> |
|||
Nim also has a rationals library for this, though it does not allow you to set tolerances like the code above. |
|||
<lang nim>import rationals |
|||
echo toRational(0.9054054054) |
|||
echo toRational(0.5185185185) |
|||
echo toRational(0.75) |
|||
echo toRational(0.1428571428) |
|||
echo toRational(35.000) |
|||
echo toRational(35.001) |
|||
echo toRational(0.9) |
|||
echo toRational(0.99) |
|||
echo toRational(0.909)</lang> |
|||
{{out}} |
|||
<pre> |
|||
67/74 |
|||
1037036407/1999998785 |
|||
3/4 |
|||
1/7 |
|||
35/1 |
|||
35001/1000 |
|||
9/10 |
|||
99/100 |
|||
909/1000 |
|||
</pre> |
</pre> |
||