Commits

Bryan O'Sullivan  committed dc8dafb

Add a "generic" function.

  • Participants
  • Parent commits 1208636

Comments (0)

Files changed (1)

File Data/Text/Format.hs

     , expt_
     , fixed
     , fixed_
+    , generic
     ) where
 
 import qualified Data.Text.Buildable as B
 right k c =
     fromLazyText . LT.justifyLeft (fromIntegral k) c . toLazyText . B.build
 
+-- ^ Render a floating point number, with the given number of decimal
+-- places.  Use decimal notation for values between @0.1@ and
+-- @9,999,999@, and scientific notation otherwise.
+generic :: (B.Buildable a, RealFloat a) =>
+         Int
+      -- ^ Number of digits of precision after the decimal.
+      -> a -> Builder
+generic decs = B.build . FPControl Generic (Just decs)
+
 -- ^ Render a floating point number using normal notation, with the
 -- given number of decimal places.
 fixed :: (B.Buildable a, RealFloat a) =>