PhilC
1
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
irkode
2
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
PhilC
3
Excellent thanks - knew it would be something simple