docs: Float 浮点数

This commit is contained in:
Shikong 2021-09-12 20:28:10 +08:00
parent 5563062616
commit eb1ba1af27

22
base/float/main.go Normal file
View File

@ -0,0 +1,22 @@
package main
import (
"fmt"
"math"
)
func main() {
var f32Min float32 = math.SmallestNonzeroFloat32
var f32Max float32 = math.MaxFloat32
// %e 科学计数法,例如 -1234.456e+78
// %E 科学计数法,例如 -1234.56E+78
// %f 有小数点而无指数,例如 123.4556
// %g 根据情况选择 %e 或 %f 以产生更紧凑的输出
// %G 根据情况选择 %E 或 %f 以产生更紧凑的输出
fmt.Printf("float32 最小值: %g, 最大值: %g\n", f32Min, f32Max)
// golang 中 所有的浮点数默认为 float64 类型
f64Min := math.SmallestNonzeroFloat64
f64Max := math.MaxFloat64
fmt.Printf("float64 最小值: %g, 最大值: %g\n", f64Min, f64Max)
}