humanize

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Byte = 1 << (iota * 10)
	KiByte
	MiByte
	GiByte
	TiByte
	PiByte
	EiByte
)

IEC Sizes. kibis of bits

View Source
const (
	IByte = 1
	KByte = IByte * 1000
	MByte = KByte * 1000
	GByte = MByte * 1000
	TByte = GByte * 1000
	PByte = TByte * 1000
	EByte = PByte * 1000
)

SI Sizes.

Variables

This section is empty.

Functions

func BigComma

func BigComma(bin *big.Int) string

BigComma produces a string form of the given big.Int in base 10 with commas after every three orders of magnitude.

func Bytes

func Bytes(s uint64) string

Bytes produces a human-readable representation of an SI size.

See also: ParseBytes.

Bytes(82854982) -> 83 MB

func BytesN

func BytesN(s uint64, n int) string

BytesN produces a human-readable representation of an SI size. n specifies the total number of digits to output, including the decimal part. If n is less than or equal to the number of digits in the integer part, the decimal part will be omitted.

See also: ParseBytes.

BytesN(82854982, 3) -> 82.9 MB BytesN(82854982, 4) -> 82.85 MB

func Comma

func Comma(v int64) string

Comma produces a string form of the given number in base 10 with commas after every three orders of magnitude.

e.g. Comma(834142) -> 834,142

func Commaf

func Commaf(v float64) string

Commaf produces a string form of the given number in base 10 with commas after every three orders of magnitude.

e.g. Commaf(834142.32) -> 834,142.32

func CommafWithDigits

func CommafWithDigits(f float64, decimals int) string

CommafWithDigits works like the Commaf but limits the resulting string to the given number of decimal places.

e.g. CommafWithDigits(834142.32, 1) -> 834,142.3

func Ftoa

func Ftoa(num float64) string

Ftoa converts a float to a string with no trailing zeros.

func FtoaWithDigits

func FtoaWithDigits(num float64, digits int) string

FtoaWithDigits converts a float to a string but limits the resulting string to the given number of decimal places, and no trailing zeros.

func IBytes

func IBytes(s uint64) string

IBytes produces a human-readable representation of an IEC size.

See also: ParseBytes.

IBytes(82854982) -> 79 MiB

func IBytesN

func IBytesN(s uint64, n int) string

IBytesN produces a human-readable representation of an IEC size. n specifies the total number of digits to output, including the decimal part. If n is less than or equal to the number of digits in the integer part, the decimal part will be omitted.

See also: ParseBytes.

IBytesN(82854982, 4) -> 79.02 MiB IBytesN(123456789, 3) -> 118 MiB IBytesN(123456789, 6) -> 117.738 MiB

func ParseBytes

func ParseBytes(s string) (uint64, error)

ParseBytes parses a string representation of bytes into the number of bytes it represents.

See Also: Bytes, IBytes.

ParseBytes("42 MB") -> 42000000, nil ParseBytes("42 mib") -> 44040192, nil

func ShortLogger

func ShortLogger(l string) string

ShortLogger 缩写 logger,除了最后一个调用方法,父级路径仅保留首位字母

Types

This section is empty.

Source Files

  • bytes.go
  • comma.go
  • ftoa.go
  • oomm.go
  • path.go

Jump to

Keyboard shortcuts

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