Search code examples
haskellghci

Make GHCi to print in decimal form.


Sometimes scientific notation leads me on to think that my result is incorrect, until I see the 'e' (e.g 2.1474027456e-2).

How do I make GHCi to print in decimal form?


Solution

  • Just use printf

    Prelude> import Text.Printf
    Prelude> printf "%f\n" (0.0000001 * exp 1)
    0.0000002718281828459045
    

    Works for a list of numbers too:

    Prelude> map (printf "%f" :: Float -> String) $ take 10 $ iterate (* exp (-1)) 1.0
    ["1.0","0.36787945","0.1353353","0.049787074","0.018315641","0.006737948","0.0024787525","0.0009118821","0.00033546268","0.00012340983"]