Documentation ¶
Index ¶
- Constants
- func Atof(s string, n ...float64) float64
- func Atoi(s string, n ...int) int
- func Atol(s string, n ...int64) int64
- func Comma(n any, c ...string) string
- func CommaFloat(v float64, c ...string) string
- func CommaFloatWithDigits(f float64, decimals int, c ...string) string
- func CommaInt(v int64, c ...string) string
- func CommaUint(v uint64, c ...string) string
- func CustomSize(format string, size float64, base float64, units []string) string
- func Ftoa(f float64) string
- func FtoaWithDigits(f float64, digits int) string
- func HumanSize(size float64) string
- func HumanSizeWithPrecision(size float64, precision int) string
- func Itoa(i int) string
- func Ltoa(i int64) string
- func MustParseSize(size string) int64
- func MustParseSizeF(size string) float64
- func ParseSize(size string) (int64, error)
- func ParseSizeF(size string) (float64, error)
Examples ¶
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func Atof ¶
Atol use strconv.ParseFloat(s, 64) to parse string 's' to float64, return n[0] if error.
func Atol ¶
Atol use strconv.ParseInt(s, 10, 64) to parse string 's' to int64, return n[0] if error.
func Comma ¶
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 e.g. Comma(834142, "_") -> 834_142
func CommaFloat ¶
CommaFloat produces a string form of the given number in base 10 with commas after every three orders of magnitude.
e.g. CommaFloat(834142.32) -> 834,142.32 e.g. CommaFloat(834142.32, "_") -> 834_142.32
func CommaFloatWithDigits ¶
CommaFloatWithDigits works like the Commaf but limits the resulting string to the given number of decimal places.
e.g. CommaFloatWithDigits(834142.32, 1) -> 834,142.3 e.g. CommaFloatWithDigits(834142.32, 1, "_") -> 834_142.3
func CommaInt ¶
CommaInt produces a string form of the given number in base 10 with commas after every three orders of magnitude.
e.g. CommaInt(834142) -> 834,142 e.g. CommaInt(834142, "_") -> 834_142
func CommaUint ¶
CommaUint produces a string form of the given number in base 10 with commas after every three orders of magnitude.
e.g. CommaUint(834142) -> 834,142 e.g. CommaUint(834142, "_") -> 834_142
func CustomSize ¶
CustomSize returns a human-readable approximation of a size using custom format.
func FtoaWithDigits ¶
FtoaWithDigits converts a float to a string but limits the resulting string to the given number of decimal places, and no trailing zeros.
func HumanSize ¶
HumanSize returns a human-readable approximation of a size capped at 4 valid numbers (eg. "2.746 MB", "796 KB").
Example ¶
fmt.Println(HumanSize(1000)) fmt.Println(HumanSize(1024)) fmt.Println(HumanSize(1000000)) fmt.Println(HumanSize(1048576)) fmt.Println(HumanSize(2 * MB)) fmt.Println(HumanSize(float64(3.42 * GB))) fmt.Println(HumanSize(float64(5.372 * TB))) fmt.Println(HumanSize(float64(2.22 * PB)))
Output:
func HumanSizeWithPrecision ¶
HumanSizeWithPrecision allows the size to be in any precision, instead of 4 digit precision used in HumanSize.
func MustParseSize ¶
MustParseSize returns an integer from a human-readable size using windows specification (KB = 1024B). panic if parse error
func MustParseSizeF ¶
MustParseSizeF returns a float64 from a human-readable size using windows specification (KB = 1024B). panic if parse error
func ParseSize ¶
ParseSize returns an integer from a human-readable size using windows specification (KB = 1024B).
Example ¶
fmt.Println(ParseSize("32")) fmt.Println(ParseSize("32b")) fmt.Println(ParseSize("32B")) fmt.Println(ParseSize("32k")) fmt.Println(ParseSize("32K")) fmt.Println(ParseSize("32kb")) fmt.Println(ParseSize("32Kb")) fmt.Println(ParseSize("32Mb")) fmt.Println(ParseSize("32Gb")) fmt.Println(ParseSize("32Tb")) fmt.Println(ParseSize("32Pb"))
Output:
func ParseSizeF ¶
ParseSizeF returns a float64 from a human-readable size using windows specification (KB = 1024B).
Types ¶
This section is empty.