Files

28 lines
761 B
Go

package main
// NumberingType controls the page numbering style rendered in the footer.
type NumberingType int
const (
NumNone NumberingType = iota // No page number (title page, declaration)
NumRoman // Roman numerals for front matter (II, III, …)
NumArabic // Arabic numerals for main body (1, 2, …)
)
// toRoman converts a positive integer to an uppercase Roman numeral string.
func toRoman(n int) string {
if n <= 0 {
return ""
}
vals := []int{1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}
syms := []string{"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}
result := ""
for i, v := range vals {
for n >= v {
n -= v
result += syms[i]
}
}
return result
}