Why doesn't my float64
have any decimal points?
I expected 40000/3
should return something like 13333.3333
package main
import (
"fmt"
)
func main() {
var f float64 = 40000 / 3
fmt.Println(f)
}
Why doesn't my float64
have any decimal points?
I expected 40000/3
should return something like 13333.3333
package main
import (
"fmt"
)
func main() {
var f float64 = 40000 / 3
fmt.Println(f)
}
40000/3 is an integer value. It is then converted to a float. To perform float division use float values. 40000.0/3 will result in a float value.