How do I get to haskell to output numbers NOT in scientific notation?
Asked Answered
G

2

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.

Gavan answered 11/11, 2011 at 18:39 Comment(1)
Related for other languages: Haskell Lua C++ ostreams DelphiAllomorphism
U
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
Unproductive answered 11/11, 2011 at 18:44 Comment(0)
C
13
> putStrLn $ Numeric.showFFloat Nothing 1e40 ""
10000000000000000000000000000000000000000.0
Consonantal answered 11/11, 2011 at 20:45 Comment(0)
U
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
Unproductive answered 11/11, 2011 at 18:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.