number

package
v2.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2024 License: Apache-2.0 Imports: 3 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 (
	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 Factorial

func Factorial(n uint64) uint64

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

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 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