Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return float number with 2 digits after decimal point?

I have some simple function

f :: Float -> Float
f x = x

Prelude> f 5.00
5.0

Why not 5.00? How can I achieve this?

like image 433
Massimo Avatar asked Sep 15 '11 18:09

Massimo


1 Answers

If you want something from base then use showGFloat:

 > import Numeric
 > showGFloat (Just 2) 1.99438 ""
 "1.99"
 > :t showGFloat
 showGFloat :: RealFloat a => Maybe Int -> a -> ShowS
like image 122
Thomas M. DuBuisson Avatar answered Sep 21 '22 18:09

Thomas M. DuBuisson