From d3799112204b9bd13132787fe3732d82bd3d433a Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Wed, 10 Apr 2024 11:04:44 +0800 Subject: [PATCH] :sparkles: Feat: add new partial function format-number --- layouts/partials/function/format-number.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 layouts/partials/function/format-number.html diff --git a/layouts/partials/function/format-number.html b/layouts/partials/function/format-number.html new file mode 100644 index 00000000..c005d2c3 --- /dev/null +++ b/layouts/partials/function/format-number.html @@ -0,0 +1,12 @@ +{{- /* How to use */ -}} +{{- /* partial "function/format-number" (dict "PRECISION" 2 "NUMBER" 5201314 */ -}} +{{- $number := .NUMBER -}} +{{- $precision := .PRECISION | default 1 -}} +{{- with $number -}} + {{- if ge . 1000 -}} + {{- $number = printf "%vk" (lang.FormatNumberCustom $precision (div . 1000.0) "- .") -}} + {{ printf "%v" $number }} + {{- end -}} +{{- end -}} + +{{- return $number -}}