This commit is contained in:
2025-04-03 12:31:01 +02:00
parent 868c870bf0
commit e16d4270c0
9 changed files with 61 additions and 114 deletions

View File

@@ -0,0 +1,32 @@
// Math utility functions for Tera templates
// Format a number with commas as thousands separators
fn format_number(num) {
let str = num.to_string();
let result = "";
let len = str.len;
for i in 0..len {
if i > 0 && (len - i) % 3 == 0 {
result += ",";
}
result += str.substr(i, 1);
}
result
}
// Calculate percentage
fn percentage(value, total) {
if total == 0 {
return "0%";
}
let pct = (value / total) * 100.0;
pct.round().to_string() + "%"
}
// Format currency
fn currency(amount, symbol) {
symbol + format_number(amount.round(2))
}