Divide By Zero Error?

First time dipping my toes into Maths functions with Hugo, so I am doing something wrong - but can’t see it.

The last statement - error calling div: can’t divide the value by 0

        {{ $Width := 600 }}
        {{ $Height := 450 }}
        {{ $aspectRatio := div $Height $Width }}
        {{ $frameWidth := div $Width $aspectRatio }}

Can anyone tell me what I am doing wrong?

Thanks

Your aspectRatio calculation returns 0.
Both values are integers and div 450 600 is 0

If you want to deal with float you have to cast one value to float.

From the doc for div

If one of the numbers is a float, the result is a float .

Which implies it’s doing integer calculation else

See: cast.ToFloat | Hugo

2 Likes

Excellent thanks - knew it would be something simple

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.