Hi,
Second day of learning Go and having some fun. I’m on Windows 7 (64 Bit) with go version go1.7.3 windows/amd64.
Kindly note:- I am not trying to point out mistakes or something, just trying to understand it. I’m not a programmer/developer. So if I end up asking something “noobish”, kindly pardon me.
I have the below script:
package main
import (
"fmt"
)
func main () {
power:= 234.735
name := "Pritesh Ugrankar"
fmt.Printf("My name is %s, and my power is, %d", name, power)
}
Then I built it so:
C:\Users\pritesh\gogo>go build go4.go
C:\Users\pritesh\gogo>
Notice, no errors thrown.
And then I executed it:
C:\Users\pritesh\gogo>go4.exe
My name is Pritesh Ugrankar, and my power is, %!d(float64=234.735)
I didn’t understand why it says %!d(float64=234.735)
. May be that is Go’s way of saying "Hey, you used a decimal when you had a float. why would you do that?"
But I thought it would be caught during compile time.
So I changed it to this:
C:\Users\pritesh\gogo>more go4.go
package main
import (
"fmt"
)
func main () {
power:= 234.735
name := "Pritesh Ugrankar"
fmt.Printf("My name is %s, and my power is, %f", name, power)
}
And built it again.
C:\Users\pritesh\gogo>go build go4.go
C:\Users\pritesh\gogo>
No errors. I am good to go.
Executed it.
C:\Users\pritesh\gogo>go4.exe
My name is Pritesh Ugrankar, and my power is, 234.735000
C:\Users\pritesh\gogo>
My question is why there was no error shown when I compiled it earlier with %d?
As stated before, I am not trying to point out mistakes or something, just trying to understand it.
Regards,
pritesh