枚举和位移
package main import ( "fmt" ) const ( B float64 = 1 << (iota * 10) KB MB GB ) func main() { fmt.Println(B) fmt.Println(KB) fmt.Println(MB) fmt.Println(GB) }
1
1024
1.048576e+06
1.073741824e+09
package main import ( "fmt" ) const ( B float64 = 1 << (iota * 10) KB MB GB ) func main() { fmt.Println(B) fmt.Println(KB) fmt.Println(MB) fmt.Println(GB) }
1
1024
1.048576e+06
1.073741824e+09