【问题标题】:How do I get to haskell to output numbers NOT in scientific notation?如何让haskell输出不是科学计数法的数字?
【发布时间】:2011-12-27 06:15:39
【问题描述】:

我有一些项目,我想将它们分成多个桶,这样每个桶都比上一个大一些。

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

我确信有一种数学上更优雅的方法可以做到这一点,但这不是我的问题。 最后一步总是以科学计数法打印出来。

如何获得纯十进制输出?我查看了 Numeric 包,但我没有快速获得任何结果。

【问题讨论】:

标签: haskell formatting scientific-notation


【解决方案1】:
> putStrLn $ Numeric.showFFloat Nothing 1e40 ""
10000000000000000000000000000000000000000.0

【讨论】:

    【解决方案2】:

    试试printf。例如:

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

    【讨论】:

      猜你喜欢
      • 2018-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-19
      • 1970-01-01
      • 2012-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多