Anonymous user
Convert decimal number to rational: Difference between revisions
Convert decimal number to rational (view source)
Revision as of 18:48, 18 November 2019
, 4 years ago→{{header|Nim}}
Line 1,595:
909//1000
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>
|