altern
altern

Reputation: 5949

Show Fractional without exponent part in Haskell

How to make Haskell show Fractional values without exponent part preserving leading zeros?

For example, command show 0.0025 outputs "2.5e-3". Is there a way to redefine this behavior?

Upvotes: 1

Views: 113

Answers (2)

Howard_Roark
Howard_Roark

Reputation: 4326

I tested first answer in this question , and it works

import Numeric
main = do
    putStrLn (showFFloat (Just 4)  0.0025 "")

Numeric module: https://hackage.haskell.org/package/base-4.14.0.0/docs/Numeric.html

Upvotes: 4

chi
chi

Reputation: 116139

You can try Text.Printf.printf. The %f format should be what you want.

> import Text.Printf
> printf "%f" 0.0025  :: String
"0.0025"

Upvotes: 3

Related Questions