Can you use Math functions on page and site variables?

Hello,

Is there a way to use mul, add etc on variables declared in page front matter or site config? I get an error with the following.

page front matter:
+++
number = 1
+++

site config:
[params]
anothernumber = 2

template:
{{ mul .Params.number .Site.Params.anothernumber }}

This gives “error calling mul: Can’t apply the operator to the values”. Also tried putting the FM and config values into variables and passing those into mul - same error.

Just interested if there is another way to use variables in calculations on-page? It appears someone has asked a similar question here but has not answered. Many thanks!

I have been able to find a workaround, however it still feels off. Any further input appreciated.

In a calculation partial:

{{ $number := (float .Params.number) }}
{{ $anothernumber := (float .Site.Params.anothernumber) }}
{{ $total := (mul $number $anothernumber) }}
{{ $total }}
1 Like

You are right!

The parameters are strings. You must use the functions float or int to convert them to a number.

1 Like

Thanks! Yes I had originally thought numbers without quotes in TOML are numerical values.