Documentation
¶
Index ¶
- func CBytesToStr(b []byte) string
- func CPtrToStr(p *byte) string
- func CopyProperties(src, dst any) error
- func DigitToChinese(s string) string
- func Float64ToStr(num float64, prec ...int) string
- func HexToInt64(str string) int64
- func Int64ToHex(num int64, args ...string) string
- func Int64ToStr(num int64) string
- func IntToHex[T gotool.Integer](v T, width ...int) string
- func IntegerToChinese(num int) string
- func StrToCBytes(s string) []byte
- func StrToCPtr(s string) *byte
- func StrToFloat32(s string) float32
- func StrToFloat64(s string) float64
- func StrToInt(s string) int
- func StrToInt8(s string) int8
- func StrToInt16(s string) int16
- func StrToInt32(s string) int32
- func StrToInt64(s string) int64
- func StrToUint(s string) uint
- func StrToUint8(s string) uint8
- func StrToUint16(s string) uint16
- func StrToUint32(s string) uint32
- func StrToUint64(s string) uint64
- func TextToChinese(text string) string
- func ToStr(value any) string
- func Uint64ToStr(num uint64) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyProperties ¶
CopyProperties 复制结构体的属性,注意:dst必须是指针类型,且指向的结构体类型与src类型相同
Params: ¶
src: 源对象 dst: 目标对象
Examples: ¶
type src struct {
Name string
Map map[string]int
}
type dst struct {
Name string
Map map[string]int
Age int
}
s1 := src{Name: "test", Map: map[string]int{"a": 1}}
s2 := new(dst)
CopyProperties(s1, s2)
func DigitToChinese ¶
DigitToChinese 数字逐位转汉字
Params ¶
s: 待转换的数字,例如:138000
Examples: ¶
DigitToChinese("138000") // 返回 一三八零零零
func Float64ToStr ¶
Float64ToStr float64转换为字符串
Params ¶
num: 待转化的数字 prec: 精度, 及就是小数点后的位数, 默认为-1, 即不限制
func Int64ToHex ¶
Int64ToHex int64转换为十六进制字符串
Params ¶
num: int64 args: 可选参数, 用于指定填充的位数以及填充的字
Examples: ¶
Int64ToHex(15) // 返回 F Int64ToHex(15, "08") // 返回 0000000F
func IntToHex ¶
IntToHex 整数转换为十六进制字符串
Params ¶
v: 待转换的整数 width: 可选参数, 用于指定输出的长度, 默认为其字节数*2
Examples: ¶
IntToHex(uint8(15)) // 输出 0F IntToHex(uint16(255)) // 输出 00FF IntToHex(int8(-15)) // 输出 F1
func IntegerToChinese ¶
IntegerToChinese 整数转中文读法
Params ¶
num: 待转换的整数
Examples: ¶
IntegerToChinese(138000) // 输出 十三万八千 IntegerToChinese(-10001) // 输出 负一万零一
func StrToCBytes ¶
StrToCBytes 字符串转换为C字节数组
Examples: ¶
StrToCBytes("hello") // 返回 []byte{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x0}
func TextToChinese ¶
TextToChinese 中文文本口语化转换
Params: ¶
text: 待处理的文本
Examples: ¶
TextToChinese("12:30") // 十二点三十分
TextToChinese("50%") // 百分之五十
TextToChinese("3.14") // 三点一四
func ToStr ¶
ToStr 常用类型转换为字符串,适用于以下类型: int, int64, int32, int16, int8, uint, uint64, uint32, uint16, uint8, float64, float32, bool, []byte, error, fmt.Stringer, ptr, map, slice, struct
Note: ¶
结构体、Map、Slice 等类型,是返回 json 序列化后的字符串
Params ¶
value: 待转换的值
Examples: ¶
ToStr(123) // 123
ToStr("123") // 123
ToStr(123.456) // 123.456
ToStr([]int{1, 2, 3}) // [1,2,3]
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.