Anonymous user
Convert decimal number to rational: Difference between revisions
Convert decimal number to rational (view source)
Revision as of 05:56, 31 August 2011
, 12 years ago→{{header|Haskell}}
Line 413:
=={{header|Haskell}}==
Note that the decimal values of the task description are truncated in some cases.
The first map finds the simplest fractions within a given radius. The last converts the string representation of the given values directly to fractions.
<lang haskell>Prelude> map (\d -> Ratio.approxRational d 0.0001) [0.9054054, 0.518518, 0.75]
[67 % 74,14 % 27,3 % 4]
|