Skip to content

Instantly share code, notes, and snippets.

@vlad-bezden
Created August 11, 2019 10:55
Show Gist options
  • Save vlad-bezden/5c22b6a765af2c58812c011a5c8c1561 to your computer and use it in GitHub Desktop.
Save vlad-bezden/5c22b6a765af2c58812c011a5c8c1561 to your computer and use it in GitHub Desktop.
How to use scientific notation in Go and convert it from float64 to int
/*
By default Go interpreter scientific notation to float64.
This example shows how to use scientific notation to declare int types.
This example also shows how to reuse the same parameter in Printf function.
*/
package main
import (
"fmt"
)
const (
kf = 1e3
ki int = 1e3
)
func main() {
fmt.Printf("ki v[%v] T[%[1]T]\n", ki)
fmt.Printf("kf v[%v] T[%[1]T]\n", kf)
}
/*
Output
ki v[1000] T[int]
kf v[1000] T[float64]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment