From feced2bdffc5d32a3e1c4d1ed66c147d83902f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kalle=20Ahlstr=C3=B6m?= Date: Mon, 9 Sep 2024 21:01:20 +0300 Subject: [PATCH] fix: also support prices lower than 100 cents --- templates/invoice.typ | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/templates/invoice.typ b/templates/invoice.typ index 7b3fc1a..5347da0 100644 --- a/templates/invoice.typ +++ b/templates/invoice.typ @@ -1,25 +1,16 @@ #let price(number) = { - let digits = "" - while number > 0 { - digits += str(calc.rem(number, 10)) - number = int(number/10) + let num_as_str = str(number) + let whole_nums="0" + if num_as_str.len() > 2 { + whole_nums = num_as_str.slice(0, -2) } - - let s = "" - let n = 0 - for d in digits { - if n == 2 { - s = "," + s - } - - if n > 2 and calc.rem(n - 2, 3) == 0 { - s = " " + s - } - - s = d + s - n += 1 + let rem = "00" + if num_as_str.len() == 1 { + rem = "0" + num_as_str + } else if num_as_str.len() >= 2 { + rem = str(num_as_str).slice(-2) } - s + whole_nums+"."+rem } #set page(