types

package
v1.0.45 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: MIT Imports: 8 Imported by: 6

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNotNum = errors.New("not a number")

Functions

func B64ToNum added in v1.0.39

func B64ToNum[N constraints.Integer | constraints.Float](str string) N

B64ToNum Base64 转换成数值.

Example
package main

import (
	"fmt"

	"github.com/xuender/kit/types"
)

func main() {
	fmt.Println(types.B64ToNum[int]("D"))
	fmt.Println(types.B64ToNum[int]("A"))
	fmt.Println(types.B64ToNum[int]("-lQL5AA"))
	fmt.Println(types.B64ToNum[int]("WU4!fR9v4"))

}
Output:

3
0
-40000000000
6284325805349880

func Bytes2Number

func Bytes2Number[T constraints.Integer | constraints.Float](data []byte) T

func FormatFloat

func FormatFloat[T constraints.Float | constraints.Integer](num T, prec int) string

FormatFloat 浮点数格式化成字符串.

func Itoa

func Itoa[T constraints.Integer | constraints.Float](num T) string

Itoa 整数转换成字符串.

func NumToB64 added in v1.0.39

func NumToB64[N constraints.Integer | constraints.Float](num N) string

NumToB64 数值转换 Base64. nolint: gomnd

Example
package main

import (
	"fmt"

	"github.com/xuender/kit/types"
)

func main() {
	fmt.Println(types.NumToB64(3))
	fmt.Println(types.NumToB64(0))
	fmt.Println(types.NumToB64(-40000000000))
	fmt.Println(types.NumToB64(6284325805349880))

}
Output:

D
A
-lQL5AA
WU4!fR9v4

func Number2Bytes

func Number2Bytes[T constraints.Integer | constraints.Float](num T) []byte

func ParseFloat

func ParseFloat[T constraints.Float](str string) (T, error)

ParseFloat 字符串转换成浮点数.

func ParseInteger

func ParseInteger[T constraints.Integer](str string) (T, error)

ParseInteger 字符串转换成整数. nolint

func ParseIntegerAny

func ParseIntegerAny[T constraints.Integer](elem any) (T, error)

ParseIntegerAny 任意类型转换成数值. nolint

func Round

func Round[I constraints.Integer, F constraints.Float](float F) I

Round 四舍五入.

func Storage added in v1.0.33

func Storage(size uint64) string
Example
package main

import (
	"fmt"

	"github.com/xuender/kit/types"
)

func main() {
	fmt.Println(types.Storage(1))
	fmt.Println(types.Storage(1024))
	fmt.Println(types.Storage(1024 * 1024))
	fmt.Println(types.Storage(1024 * 1024 * 1024))
	fmt.Println(types.Storage(1024 * 1024 * 1024 * 1024))
	fmt.Println(types.Storage(1024 * 1024 * 1024 * 1024 * 1024))
	fmt.Println(types.Storage(100000))
	fmt.Println(types.Storage(10000000))

}
Output:

1B
1K
1M
1G
1T
1P
97K
9M

Types

This section is empty.

Jump to

Keyboard shortcuts

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