/usr/local/go/bin/go build [/Users/jre/go/src/jre/template1]
Success: process exited with code 0.
/Users/jre/go/src/jre/template1/template1 [/Users/jre/go/src/jre/template1]
Sweaters: {wool 17 19.2}
Shoes: {leather 5 11.35}
17 items of wool, price 19.25 items of leather, price 11.35Success: process exited with code 0.
My two queries:
How does one ‘print’ a float value with two decimal places using text/template? I imagine this is in the docs somewhere, but I haven’t seen it yet.
You can see when I directly print the sweaters struct it shoes 19.2, but when using text/template it shows as 19.25. I can see by trial and error that it is picking up the second decimal place from the shoes struct. My question is why is it doing that? I know this is not the best way to write this code, and I should put it into a loop, but it is interesting to me that the second decimal place has been altered at all.
I understand your reply about the template line, but it’s still curious to me that only part of the template ‘placeholder’ has been overwritten. If all of Price was overwritten, or none of it, that would make sense to me. But just one number has been. I presumed from what I saw that the 0 is being removed so the value of Price for sweaters is 19.2 rather than 19.20. However… if I set the value to 19.21, I see that 19.215 is printed out, which is even more curious. Any ideas about that?
As mentioned, I know this is not the best way to write this example. I would put it into a loop, for example, to handle sweaters and shoes independently.