Documentation
¶
Index ¶
- Constants
- func Abs[T Signed](x T) T
- func AbsFloat32(x float32) float32
- func AbsFloat64(x float64) float64
- func AbsInt(x int) int
- func AbsInt16(x int16) int16
- func AbsInt32(x int32) int32
- func AbsInt64(x int64) int64
- func AlphaToInt(s string, defs ...int) int
- func Atof(s string, defs ...float64) float64
- func Atoi(s string, defs ...int) int
- func Atol(s string, defs ...int64) int64
- func Comma(n any, args ...any) string
- func CommaAny(n any, args ...any) (string, error)
- func CommaFloat(v float64, c string) string
- func CommaFloatWithDigits(f float64, digits int, c string) string
- func CommaInt(v int64, c string) string
- func CommaString(s string, c string) string
- func CommaUint(v uint64, c string) string
- func CustomSize(format string, size float64, base float64, units []string) string
- func FormatAlpha(n int) (string, error)
- func FormatRoman(n int) (string, error)
- func Ftoa(f float64) string
- func FtoaWithDigits(f float64, digits int) string
- func HumanSize(n any, args ...any) string
- func HumanSizeAny(n any, args ...any) (string, error)
- func HumanSizeFloat(size float64, precision int, separator string) string
- func IfZero[T Number](a, b T) T
- func IntToAlpha(n int) string
- func IntToRoman(n int) string
- func Itoa(n int) string
- func Ltoa(n int64) string
- func MustParseSize(size string) int64
- func MustParseSizeF(size string) float64
- func NonZero[T Number](ns ...T) T
- func ParseAlpha(s string) (int, error)
- func ParseRoman(s string) (int, error)
- func ParseSize(size string) (int64, error)
- func ParseSizeF(size string) (float64, error)
- func RomanToInt(s string, defs ...int) int
- func StripTrailingZeros(s string) string
- type Number
- type Signed
Examples ¶
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func AbsFloat32 ¶ added in v1.0.22
AbsFloat32 returns the absolute value of x.
func AbsFloat64 ¶ added in v1.0.22
AbsFloat64 returns the absolute value of x.
func AlphaToInt ¶ added in v1.0.27
AlphaToInt converts a string like "A", "Z", "AA" to a number (Excel-style).
func Atof ¶
Atol use strconv.ParseFloat(s, 64) to parse string 's' to float64, return the first non-zero value of defs if error.
func Atoi ¶
Atoi use strconv.ParseInt(s, 0, strconv.IntSize) to parse string 's' to int, return the first non-zero value of defs if error.
func Atol ¶
Atol use strconv.ParseInt(s, 0, 64) to parse string 's' to int64, return the first non-zero value of defs 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.1234, 3) -> 834,142.123 e.g. Comma(834142, "_") -> 834_142 e.g. Comma(834142.1234, "_", 3) -> 834_142.123
func CommaAny ¶ added in v1.0.27
CommaAny produces a string form of the given number in base 10 with commas after every three orders of magnitude.
e.g. CommaAny(834142) -> 834,142 e.g. CommaAny(834142.1234, 3) -> 834,142.123 e.g. CommaAny(834142, "_") -> 834_142 e.g. CommaAny(834142.1234, "_", 3) -> 834_142.123
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 CommaString ¶ added in v1.0.16
CommaString produces a string form of the given number string in base 10 with commas after every three orders of magnitude.
e.g. CommaString("834142.32") -> 834,142.32 e.g. CommaString("834142.32", "_") -> 834_142.32
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 FormatAlpha ¶ added in v1.0.27
FormatAlpha converts a positive integer to Excel-style column string.
func FormatRoman ¶ added in v1.0.27
FormatRoman converts a positive integer to roman number string.
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 with specified precision digit numbers (default: 2) (eg. "2.75 MB", "796 KB").
e.g. HumanSize(1234) -> 1.21 KB e.g. HumanSize(1234, 1) -> 1.2 KB e.g. HumanSize(1234, "") -> 1.21KB
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(3.42 * GB)) fmt.Println(HumanSize(5.372 * TB)) fmt.Println(HumanSize(2.22 * PB))
func HumanSizeAny ¶ added in v1.0.27
HumanSizeAny returns a human-readable approximation of a size with specified precision digit numbers (eg. "2.75 MB", "796 KB").
e.g. HumanSizeAny(1234) -> 1.21 KB e.g. HumanSizeAny(1234, 1) -> 1.2 KB e.g. HumanSizeAny(1234, "") -> 1.21KB
func HumanSizeFloat ¶ added in v1.0.27
HumanSizeFloat returns a human-readable approximation of a size with specified precision digit numbers (eg. "2.75 MB", "796 KB").
func IntToAlpha ¶ added in v1.0.27
IntToAlpha converts a positive integer to Excel-style column string.
func IntToRoman ¶ added in v1.0.27
IntToRoman converts a positive integer to roman number string.
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 NonZero ¶ added in v1.0.27
func NonZero[T Number](ns ...T) T
NonZero return the first non-zero value of defs if error.
func ParseAlpha ¶ added in v1.0.27
ParseAlpha converts a string like "A", "Z", "AA" to a number (Excel-style).
func ParseRoman ¶ added in v1.0.27
ParseRoman converts a roman numeric string to integer.
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"))
func ParseSizeF ¶
ParseSizeF returns a float64 from a human-readable size using windows specification (KB = 1024B).
func RomanToInt ¶ added in v1.0.27
RomanToInt converts a roman numeric string to integer.