mathutil

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: MIT Imports: 8 Imported by: 29

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConvertFail convert error
	ErrConvertFail = errors.New("convert data type is failure")
)

Functions

func DataSize

func DataSize(size uint64) string

DataSize format value. alias format.DataSize()

func ElapsedTime

func ElapsedTime(startTime time.Time) string

ElapsedTime calc elapsed time 计算运行时间消耗 单位 ms(毫秒)

func Float added in v0.2.2

func Float(in interface{}) (float64, error)

Float convert value to float64

func FloatOrPanic added in v0.5.0

func FloatOrPanic(in interface{}) float64

FloatOrPanic convert value to float64, will panic on error

func HowLongAgo

func HowLongAgo(sec int64) string

HowLongAgo calc time. alias format.HowLongAgo()

func Int added in v0.2.2

func Int(in interface{}) (int, error)

Int convert value to int

func Int64 added in v0.2.2

func Int64(in interface{}) (int64, error)

Int64 convert string to int64

func IntOrPanic added in v0.4.1

func IntOrPanic(in interface{}) int

IntOrPanic convert value to int, will panic on error

func IsNumeric added in v0.3.12

func IsNumeric(c byte) bool

IsNumeric returns true if the given character is a numeric, otherwise false.

func MustFloat added in v0.2.2

func MustFloat(in interface{}) float64

MustFloat convert value to float64 TODO will panic on error

func MustInt added in v0.2.2

func MustInt(in interface{}) int

MustInt convert value to int

func MustInt64 added in v0.2.2

func MustInt64(in interface{}) int64

MustInt64 convert

func MustString added in v0.5.0

func MustString(val interface{}) string

MustString convert intX/floatX value to string, will panic on error

func MustUint added in v0.2.2

func MustUint(in interface{}) uint64

MustUint convert string to uint

func Percent

func Percent(val, total int) float64

Percent returns a values percent of the total

func RandInt added in v0.5.0

func RandInt(min, max int) int

RandInt alias of RandomInt()

func RandIntWithSeed added in v0.5.0

func RandIntWithSeed(min, max int, seed int64) int

RandIntWithSeed alias of RandomIntWithSeed()

func RandomInt added in v0.3.6

func RandomInt(min, max int) int

RandomInt return a random int at the [min, max)

Usage:

RandomInt(10, 99)
RandomInt(100, 999)
RandomInt(1000, 9999)

func RandomIntWithSeed added in v0.5.0

func RandomIntWithSeed(min, max int, seed int64) int

RandomIntWithSeed return a random int at the [min, max)

Usage:

seed := time.Now().UnixNano()
RandomIntWithSeed(1000, 9999, seed)

func String added in v0.5.0

func String(val interface{}) string

String convert intX/floatX value to string, other type convert by fmt.Sprint

func StringOrPanic added in v0.5.0

func StringOrPanic(val interface{}) string

StringOrPanic convert intX/floatX value to string, will panic on error

func ToFloat added in v0.2.2

func ToFloat(in interface{}) (f64 float64, err error)

ToFloat convert value to float64

func ToInt added in v0.2.2

func ToInt(in interface{}) (iVal int, err error)

ToInt convert string to int

func ToInt64 added in v0.2.2

func ToInt64(in interface{}) (i64 int64, err error)

ToInt64 convert string to int64

func ToString added in v0.5.0

func ToString(val interface{}) (string, error)

ToString convert intX/floatX value to string

func ToUint added in v0.2.2

func ToUint(in interface{}) (u64 uint64, err error)

ToUint convert string to uint

func TryToString added in v0.5.0

func TryToString(val interface{}, defaultAsErr bool) (str string, err error)

TryToString try convert intX/floatX value to string

if defaultAsErr is False, will use fmt.Sprint convert other type

func Uint added in v0.2.2

func Uint(in interface{}) (uint64, error)

Uint convert string to uint

Types

This section is empty.

Jump to

Keyboard shortcuts

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