Documentation ¶
Overview ¶
Package floatKit
浮点数的高精度运算.
Package floatKit
Index ¶
- func Add(delta float64, ps ...float64) float64
- func Div(x float64, y ...float64) float64
- func DivAndRound(places int32, x float64, y ...float64) float64
- func FormatFloat32ToString(f float32, fmt byte, prec int) string
- func FormatFloat64ToString(f float64, fmt byte, prec int) string
- func Mul(delta float64, ps ...float64) float64
- func ParseStringToFloat32(str string) (float32, error)
- func ParseStringToFloat32WithDefault(str string, def float32) float32
- func ParseStringToFloat64(str string) (float64, error)
- func ParseStringToFloat64WithDefault(str string, def float64) float64
- func Sub(delta float64, ps ...float64) float64
- func ToFloat32(i interface{}) float32
- func ToFloat32E(i interface{}) (float32, error)
- func ToFloat64(i interface{}) float64
- func ToFloat64E(i interface{}) (float64, error)
- func ToReadableString(f float64) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DivAndRound ¶ added in v2.1.48
DivAndRound 除法(四舍五入),divides and rounds to a given precision
@param places 小数位数
e.g. (4, 1, 2) => 0.5 (4, 1, 3) => 0.3333 (4, 0.123456) => 0.1235
func FormatFloat32ToString ¶
FormatFloat32ToString 类型转换: float32 => string
func FormatFloat64ToString ¶
FormatFloat64ToString 类型转换: float64 => string
@param fmt (1) "f": -ddd.dddd(十进制)
(2) "b": -ddddp±ddd,指数为二进制 (3) "e": -d.dddde±dd,十进制指数 (4) "E": -d.ddddE±dd,十进制指数 (5) "g": 指数很大时用"e"格式,否则"f"格式 (6) "G": 指数很大时用"E"格式,否则"f"格式
@param prec (1) 如果传参fmt为"f"、"e"、"E",它表示小数点后的数字个数
(2) 如果传参fmt为"g"、"G",它控制总的数字个数 (3) -1: 使用"最少数量但又必需"的数字来表示传参f
func ParseStringToFloat32 ¶
ParseStringToFloat32 类型转换: string => float32
e.g. ("3.141592653589793") => 3.1415927, nil ("") => 0, strconv.ParseFloat: parsing "": invalid syntax
func ParseStringToFloat64 ¶
ParseStringToFloat64 类型转换: string => float64
e.g. ("3.141592653589793") => (3.141592653589793, nil) ("") => 0, strconv.ParseFloat: parsing "": invalid syntax
func ToFloat32E ¶
func ToFloat64E ¶
func ToReadableString ¶
ToReadableString 去除后面的无意义的"0"
PS: (1) 十进制; (2) 去掉后面的无意义的"0"; (3) 同类的方法: humanize.Ftoa().
e.g. (2.24) => "2.24" (2.0000) => "2" (2.000010000) => "2.00001"
Types ¶
This section is empty.