mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
18 lines
580 B
HTML
18 lines
580 B
HTML
{{- /*
|
|
Format a number with a specific precision and add 'k' if it's greater than 1000
|
|
Usage: {{ partial "function/format-number" (dict "PRECISION" 2 "NUMBER" 5201314) }}
|
|
Example Output: 19980.52k
|
|
*/ -}}
|
|
|
|
{{- $number := .NUMBER -}}
|
|
{{- $precision := .PRECISION | default 1 -}}
|
|
{{- with $number -}}
|
|
{{- if ge . 1000 -}}
|
|
{{- $fmtNum := lang.FormatNumberCustom $precision (div . 1000.0) "- ." -}}
|
|
{{- $fmtNum = $fmtNum | strings.TrimSuffix "0" | strings.TrimSuffix "." -}}
|
|
{{- $number = printf "%vk" $fmtNum -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- return $number -}}
|