I’m working on a freelancing project, and I’m having a very strange issue with HTML templates. The output of the program is 100 months of data as rows in an HTML table and the same output in the terminal. This output is differing. Here’s where I execute the HTML template:
combined := CombinedMonth{Basic: months, Detailed: detailedMonths}
fmt.Println(combined.Basic[99].FoodPrice)
err = template.Execute(file, combined)
if err != nil {
return err
}
Here’s the relevant part of the HTML template:
<table>
<tr>
<th>Month</th>
<th>Average wallet</th>
<th>Food price</th>
<th>Gas price</th>
<th>Coffee price</th>
</tr>
{{range $m := .Basic}}
<tr>
<td>{{$m.Month}}</td>
<td>{{$m.AverageWallet}}</td>
<td>{{$m.FoodPrice}}</td>
<td>{{$m.GasPrice}}</td>
<td>{{$m.CoffeePrice}}</td>
</tr>
{{end}}
</table>
The print statement outputs 112750.46, while the HTML has the value 11.05. There are no functions in the HTML template (rounding is done in code).