Thank you – it points on that constant, but is not that well explained.
Better to declare variable as const and both as default float64 or float32 works. As you mentioned it also treats n := 0.1 + 0.2 as constant, but not if each is declared separately.
I would not use any big math for simply arithmetic’s that is illogical to me.
Fixed point 8 decimal precision would be best but using constant trick works for simply math but difficult to use such.
package main
import "fmt"
func main() {
const a, b = 0.1, 0.2
fmt.Println("sum a(0.1) + b(0.2) = ", a+b) // Correct 0.3
fmt.Printf(" a is %T\n b is %T\n", a, b)
n := 0.1 + 0.2
fmt.Println("sum n(0.1 + 0.2) = ", n) // Correct 0.3
fmt.Printf(" n is %T\n", n)
c := 0.1
d := 0.2
fmt.Println("sum c(0.1)+ d(0.2) = ", c+d) // !!! InCorrect 0.30000000000000004
fmt.Printf(" c is %T\n d is %T\n", c, d)
Also for loop figured out will work if declared as constant it will not overflow