mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 02:18:22 +02:00
commit
9bbf73db97
@ -238,7 +238,7 @@ Output:
|
|||||||
<div>90</div>
|
<div>90</div>
|
||||||
```
|
```
|
||||||
|
|
||||||
Other operations include `add`, `mul`, and `div`.
|
Other operations include `add`, `mul`, `div` and `mod`.
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
@ -431,6 +431,7 @@ The following helper functions provided by Glance are available:
|
|||||||
- `sub(a, b float) float`: Subtracts two numbers.
|
- `sub(a, b float) float`: Subtracts two numbers.
|
||||||
- `mul(a, b float) float`: Multiplies two numbers.
|
- `mul(a, b float) float`: Multiplies two numbers.
|
||||||
- `div(a, b float) float`: Divides two numbers.
|
- `div(a, b float) float`: Divides two numbers.
|
||||||
|
- `mod(a, b int) int`: Remainder after dividing a by b (a % b).
|
||||||
- `formatApproxNumber(n int) string`: Formats a number to be more human-readable, e.g. 1000 -> 1k.
|
- `formatApproxNumber(n int) string`: Formats a number to be more human-readable, e.g. 1000 -> 1k.
|
||||||
- `formatNumber(n float|int) string`: Formats a number with commas, e.g. 1000 -> 1,000.
|
- `formatNumber(n float|int) string`: Formats a number with commas, e.g. 1000 -> 1,000.
|
||||||
- `trimPrefix(prefix string, str string) string`: Trims the prefix from a string.
|
- `trimPrefix(prefix string, str string) string`: Trims the prefix from a string.
|
||||||
|
@ -414,6 +414,14 @@ func customAPIDoMathOp[T int | float64](a, b T, op string) T {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return a / b
|
return a / b
|
||||||
|
case "mod":
|
||||||
|
ai, bi := any(a), any(b)
|
||||||
|
aint, aok := ai.(int)
|
||||||
|
bint, bok := bi.(int)
|
||||||
|
if aok && bok && bint != 0 {
|
||||||
|
return T(aint % bint)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -479,6 +487,9 @@ var customAPITemplateFuncs = func() template.FuncMap {
|
|||||||
"div": func(a, b any) any {
|
"div": func(a, b any) any {
|
||||||
return doMathOpWithAny(a, b, "div")
|
return doMathOpWithAny(a, b, "div")
|
||||||
},
|
},
|
||||||
|
"mod": func(a, b int) any {
|
||||||
|
return doMathOpWithAny(a, b, "mod")
|
||||||
|
},
|
||||||
"now": func() time.Time {
|
"now": func() time.Time {
|
||||||
return time.Now()
|
return time.Now()
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user