From 032c1e2dc6130e63c97b24f486b6d1d9d8a52a34 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Fri, 26 Apr 2024 22:07:35 +0800 Subject: [PATCH] :art: Add template func `FormatFloat` https://github.com/siyuan-note/siyuan/issues/11158 --- kernel/util/template.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/kernel/util/template.go b/kernel/util/template.go index 3e5b13ba0..00e4328fe 100644 --- a/kernel/util/template.go +++ b/kernel/util/template.go @@ -17,13 +17,15 @@ package util import ( + "math" + "text/template" + "time" + + "github.com/88250/go-humanize" "github.com/Masterminds/sprig/v3" "github.com/araddon/dateparse" "github.com/siyuan-note/logging" "github.com/spf13/cast" - "math" - "text/template" - "time" ) func BuiltInTemplateFuncs() (ret template.FuncMap) { @@ -37,6 +39,7 @@ func BuiltInTemplateFuncs() (ret template.FuncMap) { ret["log"] = log ret["logf"] = logf ret["parseTime"] = parseTime + ret["FormatFloat"] = FormatFloat return } @@ -56,3 +59,7 @@ func parseTime(dateStr string) time.Time { } return retTime } + +func FormatFloat(format string, n float64) string { + return humanize.FormatFloat(format, n) +}