feat: add formatnumber template function

This commit is contained in:
2026-06-23 17:32:18 +02:00
committed by Milas Holsting
parent 3c50fc5d53
commit 201d3479cd
2 changed files with 14 additions and 0 deletions

View File

@@ -279,6 +279,19 @@ func percent(current, total float64) float64 {
return (current / total) * 100 return (current / total) * 100
} }
func formatNumber(n int) string {
if n == 0 {
return ""
}
s := fmt.Sprintf("%d", n)
var parts []string
for i := len(s); i > 0; i -= 3 {
start := max(i-3, 0)
parts = append([]string{s[start:i]}, parts...)
}
return strings.Join(parts, " ")
}
func formatDate(dateStr string) string { func formatDate(dateStr string) string {
t, err := time.Parse(time.RFC3339, dateStr) t, err := time.Parse(time.RFC3339, dateStr)
if err != nil { if err != nil {

View File

@@ -65,6 +65,7 @@ func rendererFuncs() template.FuncMap {
"min": func(a, b int) int { return min(a, b) }, "min": func(a, b int) int { return min(a, b) },
"int": toInt, "int": toInt,
"percent": percent, "percent": percent,
"formatNumber": formatNumber,
"formatDate": formatDate, "formatDate": formatDate,
"nextSort": nextSort, "nextSort": nextSort,
"urlquery": url.QueryEscape, "urlquery": url.QueryEscape,