number

package
v2.0.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package number handler like unit cover.

Index

Examples

Constants

View Source
const (
	Bit  BitSize = 1
	Byte         = 8 * Bit
	KB           = 1000 * Byte //kilobyte
	MB           = 1000 * KB   //megabyte
	GB           = 1000 * MB   //gigabyte
	TB           = 1000 * GB   //terabyte
	PB           = 1000 * TB   //petabyte

	KiB = 1024 * Byte // kibibyte
	MiB = 1024 * KiB  //	mebibyte
	GiB = 1024 * MiB  //	gibibyte
	TiB = 1024 * GiB  //	tebibyte
	PiB = 1024 * TiB  //	pebibyte

)

1 Bytes = 8Bit byte

1 B = 8Bit byte 字节

1 KB = 1024 Bytes Kilobyte 千字节

1 MB = 1024 KB Megabyte 百万字节 兆

1 GB = 1024 MB Gigabyte 千兆 吉

1 TB = 1024 GB Terabyte 万亿字节 太

1 PB = 1024 TB Petabyte 千万亿字节 拍

1 EB = 1024 PB Exabyte 百亿亿字节 艾

1 ZB = 1024 EB Zettabyte 十万亿亿字节 泽

1 YB = 1024 ZB Yottabyte 一亿亿亿字节 尧

1 BB = 1024 YB Brontobyte

1 NB = 1024 BB NonaByte

1 DB = 1024 NB DoggaByte

View Source
const (
	// NumberStr 9+26+26+3
	NumberStr = "0123456789abcdefghijklmnopkrstuvwxyzABCDEFGHIJKLMNOPKRSTUVWXYZ+-="
	// N2 进制类型
	N2  = 2
	N8  = 8
	N16 = 16
	N32 = 32
	N36 = 36
	N62 = 62
)

@Date: 2018/12/12 0012 13:45 @Author: Joshua Conero @Name: 10 进制处理

View Source
const (
	A Unit = 1
	K      = 1000 * A
	W      = 10 * K
	M      = 1000 * K
	G      = 1000 * M
)

1k = 1000 thousand/kilo 1M = 1000_000 million 1G = 1000_000_000 billion

Variables

This section is empty.

Functions

func AnyInt64

func AnyInt64(v any) int64

func DecT36

func DecT36(num int) string

DecT36 Data conversion

func DecT62

func DecT62(num int) string

DecT62 Data conversion

func Factorial

func Factorial(n uint64) uint64

Factorial Supports factorial operations on natural numbers `n! = n*(n-1)*(n-2)*...*1`

func NumberClear

func NumberClear(s string) string

NumberClear number string clear like '_' or ','

func Round

func Round(num float64, b int) float64

Round String method processing float equal length data specified digits

func SumQInt

func SumQInt(data []int) int

SumQInt the sum value from int array

func SumQueue

func SumQueue(data []any) any

SumQueue the sum value by any number type support type: int, int8, int16, int32, int64 support type: uint, uint8, uint16, uint32, uint64 support type: float32, float64

Types

type BitSize

type BitSize int64

BitSize is a example like `time.Duration` The Bytes unit for resource file.

func Bytes

func Bytes(bytes int64) BitSize

Bytes get the bit size by bytes

func (BitSize) Bit

func (b BitSize) Bit() float64

func (BitSize) Byte

func (b BitSize) Byte() float64

func (BitSize) Format

func (b BitSize) Format() (float64, string)

Format get the format of byte size

func (BitSize) Format2

func (b BitSize) Format2() (float64, string)

Format2 get the format of byte size

func (BitSize) GB

func (b BitSize) GB() float64

func (BitSize) GiB

func (b BitSize) GiB() float64

func (BitSize) KB

func (b BitSize) KB() float64

func (BitSize) KiB

func (b BitSize) KiB() float64

func (BitSize) MB

func (b BitSize) MB() float64

func (BitSize) MiB

func (b BitSize) MiB() float64

func (BitSize) PB

func (b BitSize) PB() float64

func (BitSize) PiB

func (b BitSize) PiB() float64

func (BitSize) String

func (b BitSize) String() string

The file size default use 1024.

func (BitSize) TB

func (b BitSize) TB() float64

func (BitSize) TiB

func (b BitSize) TiB() float64

type Decimal

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

func NewDec

func NewDec(dec int) *Decimal

NewDec decimal system

func (*Decimal) T16

func (d *Decimal) T16() string

T16 16 Base system

func (*Decimal) T2

func (d *Decimal) T2() string

T2 2 Base system

func (*Decimal) T32

func (d *Decimal) T32() string

T32 32 Base system

func (*Decimal) T36

func (d *Decimal) T36() string

T36 36 Base system

func (*Decimal) T62

func (d *Decimal) T62() string

func (*Decimal) T8

func (d *Decimal) T8() string

T8 8 Base system

func (*Decimal) ToN

func (d *Decimal) ToN(base int) string

ToN convert to n-ary

type Unit

type Unit int64

func (Unit) Format

func (b Unit) Format() (float64, string)

Format get the format of byte size

func (Unit) G

func (b Unit) G() float64

func (Unit) K

func (b Unit) K() float64

func (Unit) M

func (b Unit) M() float64

func (Unit) String

func (b Unit) String() string

func (Unit) Unit

func (b Unit) Unit() float64
Example
n := Unit(5329742)
fmt.Printf("5329742: %v\n", n)
Output:

5329742: 5.3297 M

func (Unit) W

func (b Unit) W() float64

Jump to

Keyboard shortcuts

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