units

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	K = int64(1000)
	M = 1000 * K
	G = 1000 * M
	T = 1000 * G
	P = 1000 * T
	E = 1000 * P

	Ki = int64(1 << 10)
	Mi = int64(1 << 20)
	Gi = int64(1 << 30)
	Ti = int64(1 << 40)
	Pi = int64(1 << 50)
	Ei = int64(1 << 60)
)

常用单位

Variables

This section is empty.

Functions

This section is empty.

Types

type Format

type Format string

Format 单位格式

const (
	// FormatSI International System of Units
	// 十进制
	FormatSI Format = "SI"
	// FormatIEC International Electrotechnical Commission
	// 二进制
	FormatIEC Format = "IEC"
)

type Value

type Value struct {
	Value  int64
	Format Format
}

Value 值

func NewIECValue

func NewIECValue(v int64) Value

NewIECValue 创建使用 IEC 格式单位的值

func NewSIValue

func NewSIValue(v int64) Value

NewSIValue 创建使用 SI 格式单位的值

func (Value) RoundString

func (v Value) RoundString(ndigits int) string

RoundString 返回包含 ndigits 位小数的字符串形式 单位取尽可能大,但保证整数部分绝对值大于 0

func (Value) String

func (v Value) String() string

String 返回字符串形式表示

Jump to

Keyboard shortcuts

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