Search code examples
stringhaskellfloating-pointdouble

In Haskell, how to get 0.03, instead of 3.0e-2?


Basically the title. I'm trying to display floats in a string, but the result ends up being "3.0e-2" (In the example of the float "0.03"). How do I get in decimal form in Haskell? Thanks to anyone who answers.


Solution

  • For pretty formatting values of built-in types, use printf:

    > printf "%f" (0.03 :: Float)
    0.03
    

    See the linked docs for a full explanation and all possible formatting options.