Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Text.IntFormats
Description
Includes functions for converting from a string to an integer, with the base determined automatically, and from an integer to a string, with the user specifying the base. Supports negative numbers.
For examples, see the test source
for all inputs, however the reverse is not necessarily true, even in the case of
valid input, since parseInt
. showInt
True _ == RightparseInt
accepts some rather creative capitalization that showInt
does not produce.
Documentation
Constructors
Decimal |
|
Hexadecimal | Hexadecimal with lowercase digits, such as |
Octal |
|
Binary |
|
HexUpper | Hexadecimal with uppercase digits. This only affects the digits A-F, not the prefix. For example, |
parseInt :: Integral a => String -> Either String a Source #
Converts a string to an integer if able, otherwise returns an error message.
The number may begin with 0x
, 0d
, 0o
, or 0b
to specify the numerical base. If no prefix is provided, base 10 is assumed.
The prefix is case insensitive. If the number is negative, the sign goes in front of the prefix. The number must
not have leading spaces. The number may have characters following it, as long as it is not immediately followed by
a digit, a letter, or a decimal point.
Arguments
:: Integral a | |
=> Bool | Whether to include the prefix |
-> IntFormat | Which numerical base to use, and if it is hexadecimal, whether the digits are uppercase or lowercase |
-> a | The number to be converted |
-> String | The output value. |
Converts a integer to a string, with the chosen numerical base.