datatype

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: LGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractType

func ExtractType(v reflect.Value) (reflect.Value, reflect.Kind)

ExtractType gets the actual underlying type of field value.

func FormatFloat

func FormatFloat[T Float](f T) string

FormatFloat 浮点数转为字符串

func FormatInteger

func FormatInteger[T Integer](n T) string

FormatInteger 整数转为字符串

func FormatUnsigned

func FormatUnsigned[T Unsigned](u T) string

FormatUnsigned 无符号数转为字符串

func GetFinalType

func GetFinalType(v any) (rt reflect.Type)

GetFinalType 获取指针的实际类型,或数组哈希表的元素类型

func GetFloat

func GetFloat[T Float](value reflect.Value) T

GetFloat 读取浮点数值

func GetIndirectType

func GetIndirectType(v any) (rt reflect.Type)

GetIndirectType 获取对象(指针)的实际类型

func GetInteger

func GetInteger[T Integer](value reflect.Value) T

GetInteger 读取整数值

func GetUnsigned

func GetUnsigned[T Unsigned](value reflect.Value) T

GetUnsigned 读取无符号数值

func ParseFloat

func ParseFloat[T Float](s string) (T, error)

ParseFloat 字符串转为浮点数,可能失败

func ParseInteger

func ParseInteger[T Integer](s string) (T, error)

ParseInteger 字符串转为整数,可能失败

func ParseUnsigned

func ParseUnsigned[T Unsigned](s string) (T, error)

ParseUnsigned 字符串转为无符号数,可能失败

func RoundN

func RoundN(x float64, n int) float64

func SortedMapKeys

func SortedMapKeys(data any) (keys []string)

SortedMapKeys 对map的key按字母排序

Types

type Decimal

type Decimal struct {
	Value     int64 // 扩大后成为整数
	Precision int   // 小数点后位数,限制15以内
}

Decimal 高精度小数 例如 123.45 表示为 Decimal{Value:int64(12345), Precision:2}

func NewDecimal

func NewDecimal(value float64, prec int) *Decimal

NewDecimal 使用方法:NewDecimal(123.45, 2)

func ParseDecimal

func ParseDecimal(text string, prec int) *Decimal

ParseDecimal 使用方法:ParseDecimal("123.45", 2)

func (*Decimal) ChangePrecision

func (d *Decimal) ChangePrecision(offset int)

func (*Decimal) Format

func (d *Decimal) Format() string

Format 保留小数点之后末尾的0

func (*Decimal) GetFloat

func (d *Decimal) GetFloat() float64

func (*Decimal) HasFraction

func (d *Decimal) HasFraction() bool

func (*Decimal) SetFloat

func (d *Decimal) SetFloat(value float64, expand int)

func (*Decimal) SetPrecision

func (d *Decimal) SetPrecision(prec int)

func (*Decimal) String

func (d *Decimal) String() string

String 不保留小数点之后末尾的0

type Float

type Float interface {
	float64 | float32
}

Float 浮点数

type Integer

type Integer interface {
	int | int64 | int32 | int16 | int8
}

Integer 整数

type Number

type Number interface {
	Integer | Unsigned | Float
}

Number 数字类型

type Unit

type Unit []byte

Unit 数据转换单元

func (*Unit) FromBool

func (u *Unit) FromBool(b bool) error

FromBool 将布尔值转为字节码

func (Unit) FromFloat32

func (u Unit) FromFloat32(f float32) error

FromFloat32 将浮点数转为字节码

func (Unit) FromFloat64

func (u Unit) FromFloat64(f float64) error

FromFloat64 将浮点数转为字节码

func (Unit) FromInt

func (u Unit) FromInt(n int) error

FromInt 将整数转为字节码

func (Unit) FromInt16

func (u Unit) FromInt16(n int16) error

FromInt16 将整数转为字节码

func (Unit) FromInt32

func (u Unit) FromInt32(n int32) error

FromInt32 将整数转为字节码

func (Unit) FromInt64

func (u Unit) FromInt64(n int64) error

FromInt64 将整数转为字节码

func (Unit) FromInt8

func (u Unit) FromInt8(n int8) error

FromInt8 将整数转为字节码

func (Unit) FromStamp

func (u Unit) FromStamp(t time.Time) error

FromStamp 将时间戳转为字节码

func (*Unit) FromStr

func (u *Unit) FromStr(s string) error

FromStr 将字符串转为字节码

func (Unit) FromTime

func (u Unit) FromTime(t time.Time) error

FromTime 将日期时间转为字节码

func (Unit) FromUint

func (u Unit) FromUint(n uint) error

FromUint 将整数转为字节码

func (Unit) FromUint16

func (u Unit) FromUint16(n uint16) error

FromUint16 将整数转为字节码

func (Unit) FromUint32

func (u Unit) FromUint32(n uint32) error

FromUint32 将整数转为字节码

func (Unit) FromUint64

func (u Unit) FromUint64(n uint64) error

FromUint64 将整数转为字节码

func (Unit) FromUint8

func (u Unit) FromUint8(n uint8) error

FromUint8 将整数转为字节码

func (Unit) MustInt64

func (u Unit) MustInt64() int64

MustInt64 将字节码转为整数

func (Unit) String

func (u Unit) String() string

String 将字节码转为字符串

func (Unit) ToBool

func (u Unit) ToBool() (bool, error)

ToBool 将字节码转为布尔值

func (Unit) ToFloat32

func (u Unit) ToFloat32() (float32, error)

ToFloat32 将字节码转为浮点数

func (Unit) ToFloat64

func (u Unit) ToFloat64() (float64, error)

ToFloat64 将字节码转为浮点数

func (Unit) ToInt

func (u Unit) ToInt() (int, error)

ToInt 将字节码转为整数

func (Unit) ToInt16

func (u Unit) ToInt16() (int16, error)

ToInt16 将字节码转为整数

func (Unit) ToInt32

func (u Unit) ToInt32() (int32, error)

ToInt32 将字节码转为整数

func (Unit) ToInt64

func (u Unit) ToInt64() (int64, error)

ToInt64 将字节码转为整数

func (Unit) ToInt8

func (u Unit) ToInt8() (int8, error)

ToInt8 将字节码转为整数

func (Unit) ToStamp

func (u Unit) ToStamp() (t time.Time, err error)

ToStamp 将字节码转为时间戳

func (Unit) ToStr

func (u Unit) ToStr() (string, error)

ToStr 将字节码转为字符串

func (Unit) ToTime

func (u Unit) ToTime() (t time.Time, err error)

ToTime 将字节码转为日期时间

func (Unit) ToUint

func (u Unit) ToUint() (uint, error)

ToUint 将字节码转为整数

func (Unit) ToUint16

func (u Unit) ToUint16() (uint16, error)

ToUint16 将字节码转为整数

func (Unit) ToUint32

func (u Unit) ToUint32() (uint32, error)

ToUint32 将字节码转为整数

func (Unit) ToUint64

func (u Unit) ToUint64() (uint64, error)

ToUint64 将字节码转为整数

func (Unit) ToUint8

func (u Unit) ToUint8() (uint8, error)

ToUint8 将字节码转为整数

type Unsigned

type Unsigned interface {
	uint | uint64 | uint32 | uint16 | uint8
}

Unsigned 无符号数

Jump to

Keyboard shortcuts

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