1
1
mirror of https://github.com/walles/moar.git synced 2024-09-11 20:17:13 +03:00
moar/m/numberFormatter.go
Johan Walles 7e3a73f053 Three-group line numbers
Both the numbers in the left column of the file display, and the line
numbers shown in the page footer.

Fixes #6.
2021-05-21 19:38:10 +02:00

22 lines
405 B
Go

package m
import "fmt"
// Formats a number into a string with _ between each three-group of digits
func formatNumber(number uint) string {
result := ""
chars := []rune(fmt.Sprint(number))
addCount := 0
for i := len(chars) - 1; i >= 0; i-- {
char := chars[i]
if len(result) > 0 && addCount%3 == 0 {
result = "_" + result
}
result = string(char) + result
addCount++
}
return result
}