I am using %0.1f to round my float to 1 decimal places. However I am getting different results on rounding.
package main
import "fmt"
func format() {
name := "Granth"
age := 28
fmt.Print("my name is ", name, " and my age is ", age, "\n")
fmt.Printf("my name is %v and my age is %v\n", name, age)
fmt.Printf("my name is %q and my age is %v\n", name, age)
fmt.Printf("my name is %q and my age is %q\n", name, age)
fmt.Printf("name type is %T and age type is %T\n", name, age)
fmt.Printf("the float is %f\n", 34.55)
fmt.Printf("the float rounded off is %0.1f\n", 35.55)
fmt.Printf("the float rounded off is %0.1f\n", 25.55)
}
and the output is:-
my name is Granth and my age is 28
my name is Granth and my age is 28
my name is "Granth" and my age is 28
my name is "Granth" and my age is '\x1c'
name type is string and age type is int
the float is 34.550000
the float rounded off is 35.5
the float rounded off is 25.6
why is it showing 35.55 rounded as 35.5 and 25.55 rounded as 25.6?
go version go1.19.1 windows/amd64