Surprisingly I couldn't find anyone else having this same issue; I tried simply initializing a float64 in Go and printing it, then attempting a string conversion and printing that. Neither output was accurate.
I've attempted this with many fractions, including those which don't resolve to repeating decimals, as well as simply writing out the float and printing (e.g. num := 1.5 then fmt.Println(num) gives output 1).
package main
import (
"fmt"
"strconv"
)
func main() {
var num float64
num = 5/3
fmt.Printf("%v\n", num)
numString := strconv.FormatFloat(num, 'f', -1, 64)
fmt.Println(numString)
}
Expected:
// Output:
1.66
1.66
Actual:
// Output:
1
1
You wrote, using integer literals and arithmetic (x / y truncates towards zero):
Playground: https://play.golang.org/p/PBqSbpHvuSL
Output:
You should write, using floating-point literals and arithmetic:
Playground: https://play.golang.org/p/Hp1nac358HK
Output: