MtF-wiki/layouts/shortcodes/currency.html

11 lines
523 B
HTML
Raw Normal View History

2022-02-03 09:52:17 +08:00
{{- $units := slice "" "k" "M" -}}
2022-02-01 15:43:49 +08:00
{{- $from := .Get "from" -}}
2022-02-01 15:55:07 +08:00
{{- $to := default "CNY" (.Get "to") -}}
2022-02-01 15:43:49 +08:00
{{- $value := float (.Get "value") -}}
2022-02-03 09:52:17 +08:00
{{- $unit := math.Floor (div (math.Log $value) (math.Log 1000)) | int -}}
{{- $base := math.Pow 1000 $unit -}}
{{- $formatted := printf "%g%s" (div $value $base) (index $units $unit) -}}
{{- $qs := querify "Amount" $value "From" $from "To" $to -}}
<a class="currency" href="https://www.xe.com/currencyconverter/convert/?{{ $qs | safeURL }}">
{{- $formatted }} {{ $from -}}
</a>