floatKit

package
v1.30.10 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 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 Ceil

func Ceil(f float64, places int32) float64

Ceil 向上取整,类似于 math.Ceil(),但功能更强大

PS: 个人感觉: x轴向右.

e.g. (3.14, 1) => 3.2 (-3.14, 1) => -3.1

func Div

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

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

func DivRound

func DivRound(precision int32, delta float64, ps ...float64) float64

DivRound 除法(四舍五入),divides and rounds to a given precision

@param precision 小数位数

e.g. (4, 1, 2) => 0.5 (4, 1, 3) => 0.3333 (4, 0.123456) => 0.1235

func Floor

func Floor(f float64, places int32) float64

Floor 向下取整,类似于 math.Floor(),但功能更强大

PS: 个人感觉: x轴向左.

e.g. (3.14, 1) => 3.1 (-3.14, 1) => -3.2

func FormatFloat32ToString

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

FormatFloat32ToString 类型转换: float32 => string

PS: 传参可参考"Golang.docx"中的"strconv标准库".

func FormatFloat64ToString

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

FormatFloat64ToString 类型转换: float64 => string

PS: 传参可参考"Golang.docx"中的"strconv标准库".

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 Round

func Round(f float64, places int32) float64

Round 保留小数位(四舍五入),类似于 math.Round(),但功能更强大

PS: (1) 参考:https://zhuanlan.zhihu.com/p/152050239?from_voters_page=true (2) 个人感觉:先把正负号拿出来 => 进行取舍 => 把正负号还回去 (3) 传参为负数的情况下,Golang的四舍五入与别的语言(Java、JavaScript)不同,详情见"Golang.docx"中的"math标准库".

@param places 小数位数(如果最后几个都是0的话,会省略掉);可以为负值

e.g. (3.14, 1) => 3.1 (3.15, 1) => 3.2 (-3.14, 1) => -3.1 (-3.15, 1) => -3.2

(3.1001, 2) => 3.1 (521, -1) => 520

func Sub

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

Sub 减

func ToFloat32

func ToFloat32(obj interface{}) float32

func ToFloat32WithDefault

func ToFloat32WithDefault(obj interface{}, def float32) float32

func ToFloat32WithDefaultE

func ToFloat32WithDefaultE(obj interface{}, def float32) (float32, error)

func ToFloat64

func ToFloat64(obj interface{}) float64

func ToFloat64WithDefault

func ToFloat64WithDefault(obj interface{}, def float64) float64

func ToFloat64WithDefaultE

func ToFloat64WithDefaultE(obj interface{}, def float64) (float64, error)

Types

type Float32

type Float32 struct {
	// contains filtered or unexported fields
}

func NewFloat32

func NewFloat32(value float32) *Float32

func (*Float32) GetValue

func (c *Float32) GetValue() float32

type Float64

type Float64 struct {
	// contains filtered or unexported fields
}

func NewFloat64

func NewFloat64(value float64) *Float64

func (*Float64) GetValue

func (c *Float64) GetValue() float64

Jump to

Keyboard shortcuts

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