16

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.

Chris Martin
  • 29,484
  • 8
  • 71
  • 131
nont
  • 9,072
  • 6
  • 61
  • 80
  • 1
    Related for other languages: [Haskell](http://stackoverflow.com/questions/8098457/how-do-i-get-to-haskell-to-output-numbers-not-in-scientific-notation) [Lua](http://stackoverflow.com/questions/1133639/how-can-i-print-a-huge-number-in-lua-without-using-scientific-notation) [C++ ostreams](http://stackoverflow.com/questions/2335657/prevent-scientific-notation-in-ostream-when-using-with-double) [Delphi](http://stackoverflow.com/questions/6077153/how-to-disable-scientific-notation-in-asstring-in-delphi) – Mechanical snail Aug 22 '12 at 03:39

2 Answers2

13
> putStrLn $ Numeric.showFFloat Nothing 1e40 ""
10000000000000000000000000000000000000000.0
newacct
  • 115,460
  • 28
  • 157
  • 222
11

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
jameshfisher
  • 29,645
  • 26
  • 105
  • 155
Claudiu
  • 216,039
  • 159
  • 467
  • 667