Documentation
¶
Overview ¶
Package wordnumber provides a set of methods to convert numbers into various 'word' representations
Currently that means cardinal and ordinal numbers in british english using the short scale, plus roman numerals
Index ¶
- Constants
- func CardinalToInt(s string) (int, error)
- func IntToCardinal(i int) string
- func IntToOrdinal(i int) (string, error)
- func IntToOrdinalShort(i int) (string, error)
- func IntToRoman(i int) (string, error)
- func OrdinalShortToInt(s string) (int, error)
- func OrdinalToInt(s string) (int, error)
- func PrintedLen(s string) (res int)
- func RomanToInt(s string) (res int, err error)
- func Version() string
- type Error
- type Group
Constants ¶
const MaxRoman = 1_000_000*4 - 1
MaxRoman is the largest roman numeral that can be represented
Variables ¶
This section is empty.
Functions ¶
func CardinalToInt ¶
CardinalToInt converts a word description for a number into an int
eg. "one hundred and four" => 104
func IntToCardinal ¶
IntToCardinal returns the word form of the given number
eg. 37 => "thirty seven"
func IntToOrdinal ¶
IntToOrdinal returns the given number as a ordinal word, eg 13 => thirteenth
func IntToOrdinalShort ¶
IntToOrdinalShort returns the given number as an ordinal number in short form, eg 13 => 13th
func OrdinalShortToInt ¶
OrdinalShortToInt converts a word description for a short ordinal number into an int
eg. "104th" => 104
func OrdinalToInt ¶
OrdinalToInt converts a word description for an ordinal number into an int
eg. "one hundred and fourth" => 104
func PrintedLen ¶
PrintedLen returns the printed length of a string, ie the number of cells on a terminal it uses
this method is useful because the extended roman numerals use combining unicode characters to render the over-bar. That means
len("M̄") == 2 // ie the number of runes in the string
and
PrintedLen("M̄") == 1
func RomanToInt ¶
RomanToInt returns the decimal value of the given roman numeral
Types ¶
type Error ¶
type Error string
Error is the error type returned from this package
const ( ErrNotImplemented Error = "method '%s' is not yet implemented" ErrOutOfRange Error = "number out of range" ErrNegative Error = "cannot represent negative numbers" ErrFmtOverflow Error = "cannot represent numbers greater than %d" ErrUnknownConversion Error = "unknown conversion method %s" ErrParseCardinal Error = "unknown word '%s' in expression, can't parse as a cardinal number" ErrParseOrdinal Error = "unknown word '%s' in expression, can't parse as an ordinal number" ErrParseShortOrdinal Error = "can't parse '%s' as a short ordinal number" ErrBadRoman Error = "unexpected character parsing roman numerals" ErrParseInit Error = "could not process '%s' as an integer" ErrNoInput Error = "no input was provided" )
Possible errors returned from this package
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
example
example printing of a selection of numbers in formats provided by the wordnumber library
|
example printing of a selection of numbers in formats provided by the wordnumber library |
wordnumber
wordnumber converts an integer to various 'word' formats (and back) Usage: wordnumber [-i] [-c|-o|-s|-r] <int> wordnumber -v wordnumber -h -h, --help this message -c, --cardinal display the number given in cardinal form (eg 12 -> 'twelve') (default true) -o, --ordinal display the number given in ordinal form (eg 12 -> 'twelfth') -s, --short-ordinal display the number given in short ordinal form (eg 12 -> '12th') -r, --roman display the number given in roman form (eg 12 -> 'XII') -i, --inverse perform the inverse operation (eg with -i -c 'twelve' -> 12) -v, --version display the version
|
wordnumber converts an integer to various 'word' formats (and back) Usage: wordnumber [-i] [-c|-o|-s|-r] <int> wordnumber -v wordnumber -h -h, --help this message -c, --cardinal display the number given in cardinal form (eg 12 -> 'twelve') (default true) -o, --ordinal display the number given in ordinal form (eg 12 -> 'twelfth') -s, --short-ordinal display the number given in short ordinal form (eg 12 -> '12th') -r, --roman display the number given in roman form (eg 12 -> 'XII') -i, --inverse perform the inverse operation (eg with -i -c 'twelve' -> 12) -v, --version display the version |