number

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 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 added in v1.1.0

func AnyInt64(v any) int64

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 added in v1.1.0

type BitSize int64

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

func Bytes added in v1.1.0

func Bytes(bytes int64) BitSize

Bytes get the bit size by bytes

func (BitSize) Bit added in v1.1.0

func (b BitSize) Bit() float64

func (BitSize) Byte added in v1.1.0

func (b BitSize) Byte() float64

func (BitSize) Format added in v1.1.0

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

Format get the format of byte size

func (BitSize) Format2 added in v1.1.0

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

Format2 get the format of byte size

func (BitSize) GB added in v1.1.0

func (b BitSize) GB() float64

func (BitSize) GiB added in v1.1.0

func (b BitSize) GiB() float64

func (BitSize) KB added in v1.1.0

func (b BitSize) KB() float64

func (BitSize) KiB added in v1.1.0

func (b BitSize) KiB() float64

func (BitSize) MB added in v1.1.0

func (b BitSize) MB() float64

func (BitSize) MiB added in v1.1.0

func (b BitSize) MiB() float64

func (BitSize) PB added in v1.1.0

func (b BitSize) PB() float64

func (BitSize) PiB added in v1.1.0

func (b BitSize) PiB() float64

func (BitSize) String added in v1.1.0

func (b BitSize) String() string

The file size default use 1024.

func (BitSize) TB added in v1.1.0

func (b BitSize) TB() float64

func (BitSize) TiB added in v1.1.0

func (b BitSize) TiB() float64

type Unit added in v1.1.0

type Unit int64

func (Unit) Format added in v1.1.0

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

Format get the format of byte size

func (Unit) G added in v1.1.0

func (b Unit) G() float64

func (Unit) K added in v1.1.0

func (b Unit) K() float64

func (Unit) M added in v1.1.0

func (b Unit) M() float64

func (Unit) String added in v1.1.0

func (b Unit) String() string

func (Unit) Unit added in v1.1.0

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

5329742: 5.3297 M

func (Unit) W added in v1.1.0

func (b Unit) W() float64

Jump to

Keyboard shortcuts

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