https://github.com/brandenc40/romannumeral
Convert to and from roman numerals in Go.
https://github.com/brandenc40/romannumeral
go golang numeral numerals roman roman-numeral roman-numerals
Last synced: about 1 month ago
JSON representation
Convert to and from roman numerals in Go.
- Host: GitHub
- URL: https://github.com/brandenc40/romannumeral
- Owner: brandenc40
- License: apache-2.0
- Created: 2021-02-07T21:00:47.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-06T02:48:20.000Z (about 4 years ago)
- Last Synced: 2025-04-11T05:49:40.974Z (about 1 month ago)
- Topics: go, golang, numeral, numerals, roman, roman-numeral, roman-numerals
- Language: Go
- Homepage:
- Size: 31.3 KB
- Stars: 3
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Roman Numerals
[](https://pkg.go.dev/github.com/brandenc40/romannumeral)
[](https://codecov.io/gh/brandenc40/romannumeral)
## Quickly and efficiently convert to and from roman numerals in Go.A reliable module using the most efficient methods possible for converting between
roman numerals and integers in Go. Algorithms adopted from [here](https://rosettacode.org/wiki/Roman_numerals).### Benchmark Results
```sh
goos: darwin
goarch: arm64
pkg: github.com/brandenc40/romannumeral
BenchmarkIntToString-8 56474846 20.84 ns/op 0 B/op 0 allocs/op
BenchmarkIntToBytes-8 48157634 24.36 ns/op 0 B/op 0 allocs/op
BenchmarkStringToInt-8 17584252 67.28 ns/op 0 B/op 0 allocs/op
BenchmarkBytesToInt-8 18343551 64.77 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/brandenc40/romannumeral 6.111s
```### Example
```go
package mainimport (
"fmt"
rom "github.com/brandenc40/romannumeral"
)func ExampleStringToInt() {
integer, err := rom.StringToInt("IV")
if err != nil {
panic(err)
}
fmt.Println(integer == 4) // True
}func ExampleBytesToInt() {
integer, err := rom.BytesToInt([]byte("IV"))
if err != nil {
panic(err)
}
fmt.Println(integer == 4) // True
}func ExampleIntToString() {
roman, err := rom.IntToString(4)
if err != nil {
panic(err)
}
fmt.Println(roman == "IV") // True
}func ExampleIntToBytes() {
roman, err := rom.IntToBytes(4)
if err != nil {
panic(err)
}
fmt.Println(string(roman) == "IV") // True
}
```