Skip to content

Commit

Permalink
fix: also support prices lower than 100 cents
Browse files Browse the repository at this point in the history
  • Loading branch information
kahlstrm committed Sep 9, 2024
1 parent 05a32e5 commit feced2b
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions templates/invoice.typ
Original file line number Diff line number Diff line change
@@ -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(
Expand Down

0 comments on commit feced2b

Please sign in to comment.