non*_*ont 16 formatting haskell scientific-notation
我有一些项目要分区为多个桶,这样每个桶比最后一个桶大一些.
items = 500
chunks = 5
increment = 0.20
{- find the proportions -}
sizes = take chunks (iterate (+increment) 1)
base = sum sizes / items
buckets = map (base *) sizes
main = print buckets
Run Code Online (Sandbox Code Playgroud)
我确信有一种数学上更优雅的方式来做到这一点,但这不是我的问题.最后一步始终以科学记数法打印出来.
如何获得纯十进制输出?我看过Numeric包,但是我的速度很快.
new*_*cct 12
> putStrLn $ Numeric.showFFloat Nothing 1e40 ""
10000000000000000000000000000000000000000.0
Run Code Online (Sandbox Code Playgroud)
Cla*_*diu 11
试试printf.例如:
> import Text.Printf
> printf "%d\n" (23::Int)
23
> printf "%s %s\n" "Hello" "World"
Hello World
> printf "%.2f\n" pi
3.14
Run Code Online (Sandbox Code Playgroud)