You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import "fmt"
func main() {
a, b := 2.2, 2.2
fmt.Println(a + b)
a, b = 2.2, 2.3
fmt.Println(a + b)
a, b = 2.2, 4.4
fmt.Println(a + b)
a, b = 1.1, 2.2
fmt.Println(a + b)
}
What did you expect to see?
4.4
4.5
6.6
3.3
What did you see instead?
4.4
4.5
6.6000000000000005
3.3000000000000003
The text was updated successfully, but these errors were encountered:
Println shows 6.6000000000000005 because it's closer to the actual value of 2.2 + 4.4 in IEEE-754 float64 arithmetic. If you want to truncate the value, use Printf and %f, e.g.
a, b := 2.2, 4.4
fmt.Printf("%.2f", a + b) // prints 6.60
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Not sure.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: