让 GHCi 以十进制形式打印。

Make GHCi to print in decimal form.

有时科学计数法会让我认为我的结果不正确,直到我看到“e”(例如 2.1474027456e -2).

如何让 GHCi 以十进制形式打印?

只需使用printf

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

适用于数字列表:

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"]