17

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
  • 30,334
  • 10
  • 78
  • 137
nont
  • 9,322
  • 7
  • 62
  • 82
  • 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
  • 119,665
  • 29
  • 163
  • 224
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
  • 34,029
  • 31
  • 121
  • 167
Claudiu
  • 224,032
  • 165
  • 485
  • 680