diff --git a/app/Main.hs b/app/Main.hs index 5644a65..0100982 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -16,10 +16,10 @@ main = ioLoop precision = 5 :: Int showRatio :: Int -> Rational -> String -showRatio p r = (if (r < 0) then "-" else "") ++ prepoint_digits ++ "." ++ postpoint_digits +showRatio p r = (if (r < 0) then "-" else "") ++ prepoint_digits ++ (if (length postpoint_digits > 0) then ("." ++ postpoint_digits) else "") where prepoint_digits = init . show . round . abs $ (r * 10) - postpoint_digits = (take p) . (drop (length prepoint_digits)) . show . round . abs $ (r * 10^p) + postpoint_digits = reverse .dropWhile (=='0') . reverse .(take p) . (drop (length prepoint_digits)) . show . round . abs $ (r * 10^p) useResult (Right e) = (showRatio precision) . evaluate $ replaceVars e vars useResult (Left e) = show e