How do I get to haskell to output numbers NOT in scientific notation?

时光毁灭记忆、已成空白 提交于 2019-11-28 02:40:10

问题


I have a some items that I want to partition in to a number of buckets, such that each bucket is some fraction larger than the last.

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

I'm sure there is a mathematically more elegant way to do this, but that's not my question. The end step is always printing out in scientific notation.

How do I get plain decimal output? I've looked at the Numeric package but I'm getting nowhere fast.


回答1:


Try printf. e.g.:

> import Text.Printf
> printf "%d\n" (23::Int)
23
> printf "%s %s\n" "Hello" "World"
Hello World
> printf "%.2f\n" pi
3.14



回答2:


> putStrLn $ Numeric.showFFloat Nothing 1e40 ""
10000000000000000000000000000000000000000.0


来源:https://stackoverflow.com/questions/8098457/how-do-i-get-to-haskell-to-output-numbers-not-in-scientific-notation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!