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

Time:10-25

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.

CodePudding user response:

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.

  • Related