Created
August 11, 2019 10:55
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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