floatKit

package
v3.0.61 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package floatKit

浮点数的高精度运算.

Package floatKit

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(delta float64, ps ...float64) float64

Add 加

func Div

func Div(x float64, y ...float64) float64

Div 除法(不额外处理小数位)

func DivAndRound

func DivAndRound(places int32, x float64, y ...float64) float64

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

func FormatFloat32ToString(f float32, fmt byte, prec int) string

FormatFloat32ToString 类型转换: float32 => string

func FormatFloat64ToString

func FormatFloat64ToString(f float64, fmt byte, prec int) string

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 Mul

func Mul(delta float64, ps ...float64) float64

Mul 乘

func ParseStringToFloat32

func ParseStringToFloat32(str string) (float32, error)

ParseStringToFloat32 类型转换: string => float32

e.g. ("3.141592653589793") => 3.1415927, nil ("") => 0, strconv.ParseFloat: parsing "": invalid syntax

func ParseStringToFloat32WithDefault

func ParseStringToFloat32WithDefault(str string, def float32) float32

func ParseStringToFloat64

func ParseStringToFloat64(str string) (float64, error)

ParseStringToFloat64 类型转换: string => float64

e.g. ("3.141592653589793") => (3.141592653589793, nil) ("") => 0, strconv.ParseFloat: parsing "": invalid syntax

func ParseStringToFloat64WithDefault

func ParseStringToFloat64WithDefault(str string, def float64) float64

func Sub

func Sub(delta float64, ps ...float64) float64

Sub 减

func ToFloat32

func ToFloat32(i interface{}) float32

func ToFloat32E

func ToFloat32E(i interface{}) (float32, error)

func ToFloat64

func ToFloat64(i interface{}) float64

func ToFloat64E

func ToFloat64E(i interface{}) (float64, error)

func ToReadableString

func ToReadableString(f float64) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL