Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a "generic" function.

  • Loading branch information...
commit a2493d77815918fe8025675a301995aace744c93 1 parent c7ccdb8
@bos authored
Showing with 10 additions and 0 deletions.
  1. +10 −0 Data/Text/Format.hs
View
10 Data/Text/Format.hs
@@ -34,6 +34,7 @@ module Data.Text.Format
, expt_
, fixed
, fixed_
+ , generic
) where
import qualified Data.Text.Buildable as B
@@ -83,6 +84,15 @@ right :: B.Buildable a => Int -> Char -> a -> Builder
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) =>
Please sign in to comment.
Something went wrong with that request. Please try again.