如何让haskell输出不是科学计数法的数字? [英] How do I get to haskell to output numbers NOT in scientific notation?

查看:25
本文介绍了如何让haskell输出不是科学计数法的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些项目想要划分为多个桶,这样每个桶都比上一个大一些.

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.

如何获得纯十进制输出?我看过 Numeric 包但是我的速度很快.

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

推荐答案

试试 printf.例如:

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

这篇关于如何让haskell输出不是科学计数法的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆