-1

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)
}

https://play.golang.org/p/OxjLjwPGYhx

shmsr
  • 3,802
  • 2
  • 18
  • 29
user1406186
  • 940
  • 3
  • 16
  • 28

1 Answers1

2

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.

y_159
  • 458
  • 3
  • 15
Burak Serdar
  • 46,455
  • 3
  • 40
  • 59