我怎样才能让Haskell以科学记数法输出数字? [英] How do I get to haskell to output numbers NOT in scientific notation?
本文介绍了我怎样才能让Haskell以科学记数法输出数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些项目,我想分区到一些桶,这样每个桶是比最后一个分数大一些。
items = 500
chunks = 5
increment = 0.20
{ - 找到比例 - }
sizes = take chunk (迭代(+增量)1)
基数=总和大小/项目
存储区=地图(基本*)大小
main =打印存储区
我确信有一个数学上更优雅的方法来做到这一点,但这不是我的问题。
结束步骤始终以科学记数法打印出来。
如何获得普通的十进制输出?我查看了数字包,但
解决方案
试试 printf 。例如:
> import Text.Printf
> printf%d \\\
(23 :: Int)
23
> printf%s%s \\\
HelloWorld
Hello World
> printf%.2f\\\
pi
3.14
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.
解决方案
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
这篇关于我怎样才能让Haskell以科学记数法输出数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文