guibou / PyF

Haskell QuasiQuoter for String Formatting
BSD 3-Clause "New" or "Revised" License
66 stars 13 forks source link

:g does not behave as python for floating point numbers #126

Open guibou opened 1 year ago

guibou commented 1 year ago

With PyF:

ghci> x = 1.0 :: Double
ghci> [fmt|{x}|]
"1.0"
ghci> [fmt|{x:g}|]
"1.000000"

In Python

>>> f"{1.0:g}"
'1'

That's convenient because it allows the user to trim the trailing 0 and . if any.

eltix commented 2 months ago

@guibou Same issue for Rational:

ghci> [fmt|{(2::Rational):.2g}|]
"2.00"

Here, one would have expected "2" as a result