Documentation
¶
Overview ¶
Converts between integers and Roman Numeral strings.
Currently only supports Roman Numerals without viniculum (1-3999) and will throw an error for numbers outside of that range. See here for details on viniculum: https://en.wikipedia.org/wiki/Roman_numerals#Large_numbers
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( InvalidRomanNumeral = errors.New("invalid roman numeral") IntegerOutOfBounds = errors.New("integer must be between 1 and 3999") )
Functions ¶
func BytesToInt ¶ added in v1.1.5
BytesToInt converts a roman numeral byte array to an integer. Roman numerals for numbers outside of the range 1 to 3,999 will return an error. Nil or empty []byte will return 0 with no error thrown.
Example ¶
input := []byte("IV") integer, err := BytesToInt(input) if err != nil { panic(err) } fmt.Println(integer == 4) // True
Output:
func IntToBytes ¶ added in v1.1.5
IntToBytes converts an integer value to a roman numeral byte array. An error is returned if the integer is not between 1 and 3999.
Example ¶
roman, err := IntToBytes(4) if err != nil { panic(err) } fmt.Println(string(roman) == "IV") // True
Output:
func IntToString ¶ added in v1.1.5
IntToString converts an integer value to a roman numeral string. An error is returned if the integer is not between 1 and 3999.
Example ¶
roman, err := IntToString(4) if err != nil { panic(err) } fmt.Println(roman == "IV") // True
Output:
func StringToInt ¶ added in v1.1.5
StringToInt converts a roman numeral string to an integer. Roman numerals for numbers outside of the range 1 to 3,999 will return an error. Empty strings will return 0 with no error thrown.
Example ¶
integer, err := StringToInt("IV") if err != nil { panic(err) } fmt.Println(integer == 4) // True
Output:
Types ¶
This section is empty.