|
| MissingH.Quantity | | Portability | portable | | Stability | provisional | | Maintainer | John Goerzen <jgoerzen@complete.org> |
|
|
|
| Description |
Tools for rendering sizes
Written by John Goerzen, jgoerzen@complete.org
|
|
| Synopsis |
|
|
|
| Documentation |
|
| renderNum |
| :: (Ord a, Real a) | | | => SizeOpts | | | -> Int | Precision of the result
| | -> a | The number to examine
| | -> String | | Render a number into a string, based on the given quantities. This is
useful for displaying quantities in terms of bytes or in SI units. Give this
function the SizeOpts for the desired output, and a precision (number of
digits to the right of the decimal point), and you get a string output.
Here are some examples:
MissingH.Quantity> renderNum binaryOpts 0 1048576
"1M"
MissingH.Quantity> renderNum binaryOpts 2 10485760
"10.00M"
MissingH.Quantity> renderNum binaryOpts 3 1048576
"1.000M"
MissingH.Quantity> renderNum binaryOpts 3 1500000
"1.431M"
MissingH.Quantity> renderNum binaryOpts 2 (1500 ** 3)
"3.14G"
MissingH.Quantity> renderNum siOpts 2 1024
"1.02k"
MissingH.Quantity> renderNum siOpts 2 1048576
"1.05M"
MissingH.Quantity> renderNum siOpts 2 0.001
"1.00m"
MissingH.Quantity> renderNum siOpts 2 0.0001
"100.00u"
If you want more control over the output, see quantifyNum.
|
|
|
| quantifyNum :: (Ord a, Real a, Floating b, Ord b) => SizeOpts -> a -> (b, Char) |
| Takes a number and returns a new (quantity, suffix) combination.
The space character is used as the suffix for items around 0.
|
|
| data SizeOpts |
| The options for quantifyNum and renderNum
| | Constructors | | SizeOpts | | | base :: Int | The base from which calculations are made
| | powerIncr :: Int | The increment to the power for each new suffix
| | firstPower :: Int | The first power for which suffixes are given
| | suffixes :: String | The suffixes themselves
|
|
|
|
|
| binaryOpts :: SizeOpts |
| Predefined definitions for byte measurement in groups of 1024, from 0 to
2**80
|
|
| siOpts :: SizeOpts |
| Predefined definitions for SI measurement, from 10**-24 to 10**24.
|
|
| Produced by Haddock version 0.8 |