Take the 2-minute tour ×

I have some simple function

f :: Float -> Float
f x = x

Prelude> f 5.00

Why not 5.00? How can I achieve this?

share|improve this question
What are you actually trying to achieve. Looking at your questing it looks like you don't understand floating point numbers. –  augustss Sep 16 '11 at 1:05

2 Answers 2

If you want something from base then use showGFloat:

 > import Numeric
 > showGFloat (Just 2) 1.99438 ""
 > :t showGFloat
 showGFloat :: RealFloat a => Maybe Int -> a -> ShowS
share|improve this answer
Thanks, it was useful! –  Massimo Sep 15 '11 at 18:58

You can use printf

printf "%.2f" (f :: Float)
share|improve this answer
Joe, thanks a lot! –  Massimo Sep 15 '11 at 18:28
The code above throws some errors (Couldn't match expected type Float with actual type Float -> Float). So I used this one: line n = printf "%.2f\n" $ f n. –  Massimo Sep 15 '11 at 18:53

Your Answer


