package humanize
Import Path
github.com/dustin/go-humanize (on go.dev)
Dependency Relation
imports 11 packages, and imported by one package
Involved Source Files
big.go
bigbytes.go
bytes.go
comma.go
commaf.go
ftoa.go
Package humanize converts boring ugly numbers to human-friendly strings and back.
Durations can be turned into strings such as "3 days ago", numbers
representing sizes like 82854982 into useful strings like, "83 MB" or
"79 MiB" (whichever you prefer).
number.go
ordinals.go
si.go
times.go
Package-Level Type Names (only one)
A RelTimeMagnitude struct contains a relative time point at which
the relative format of time will switch to a new format string. A
slice of these in ascending order by their "D" field is passed to
CustomRelTime to format durations.
The Format field is a string that may contain a "%s" which will be
replaced with the appropriate signed label (e.g. "ago" or "from
now") and a "%d" that will be replaced by the quantity.
The DivBy field is the amount of time the time difference must be
divided by in order to display correctly.
e.g. if D is 2*time.Minute and you want to display "%d minutes %s"
DivBy should be time.Minute so whatever the duration is will be
expressed in minutes.
D time.Duration
DivBy time.Duration
Format string
func CustomRelTime(a, b time.Time, albl, blbl string, magnitudes []RelTimeMagnitude) string
Package-Level Functions (total 23)
BigBytes produces a human readable representation of an SI size.
See also: ParseBigBytes.
BigBytes(82854982) -> 83 MB
BigComma produces a string form of the given big.Int in base 10
with commas after every three orders of magnitude.
BigCommaf produces a string form of the given big.Float in base 10
with commas after every three orders of magnitude.
BigIBytes produces a human readable representation of an IEC size.
See also: ParseBigBytes.
BigIBytes(82854982) -> 79 MiB
Bytes produces a human readable representation of an SI size.
See also: ParseBytes.
Bytes(82854982) -> 83 MB
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
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
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
ComputeSI finds the most appropriate SI prefix for the given number
and returns the prefix along with the value adjusted to be within
that prefix.
See also: SI, ParseSI.
e.g. ComputeSI(2.2345e-12) -> (2.2345, "p")
CustomRelTime formats a time into a relative string.
It takes two times two labels and a table of relative time formats.
In addition to the generic time delta string (e.g. 5 minutes), the
labels are used applied so that the label corresponding to the
smaller time is applied.
FormatFloat produces a formatted number as string based on the following user-specified criteria:
* thousands separator
* decimal separator
* decimal precision
Usage: s := RenderFloat(format, n)
The format parameter tells how to render the number n.
See examples: http://play.golang.org/p/LXc1Ddm1lJ
Examples of format strings, given n = 12345.6789:
"#,###.##" => "12,345.67"
"#,###." => "12,345"
"#,###" => "12345,678"
"#\u202F###,##" => "12 345,68"
"#.###,###### => 12.345,678900
"" (aka default format) => 12,345.67
The highest precision allowed is 9 digits after the decimal symbol.
There is also a version for integer number, FormatInteger(),
which is convenient for calls within template.
FormatInteger produces a formatted number as string.
See FormatFloat.
Ftoa converts a float to a string with no trailing zeros.
FtoaWithDigits converts a float to a string but limits the resulting string
to the given number of decimal places, and no trailing zeros.
IBytes produces a human readable representation of an IEC size.
See also: ParseBytes.
IBytes(82854982) -> 79 MiB
Ordinal gives you the input number in a rank/ordinal format.
Ordinal(3) -> 3rd
ParseBigBytes parses a string representation of bytes into the number
of bytes it represents.
See also: BigBytes, BigIBytes.
ParseBigBytes("42 MB") -> 42000000, nil
ParseBigBytes("42 mib") -> 44040192, nil
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
ParseSI parses an SI string back into the number and unit.
See also: SI, ComputeSI.
e.g. ParseSI("2.2345 pF") -> (2.2345e-12, "F", nil)
RelTime formats a time into a relative string.
It takes two times and two labels. In addition to the generic time
delta string (e.g. 5 minutes), the labels are used applied so that
the label corresponding to the smaller time is applied.
RelTime(timeInPast, timeInFuture, "earlier", "later") -> "3 weeks earlier"
SI returns a string with default formatting.
SI uses Ftoa to format float value, removing trailing zeros.
See also: ComputeSI, ParseSI.
e.g. SI(1000000, "B") -> 1 MB
e.g. SI(2.2345e-12, "F") -> 2.2345 pF
SIWithDigits works like SI but limits the resulting string to the
given number of decimal places.
e.g. SIWithDigits(1000000, 0, "B") -> 1 MB
e.g. SIWithDigits(2.2345e-12, 2, "F") -> 2.23 pF
Time formats a time into a relative string.
Time(someT) -> "3 weeks ago"
Package-Level Variables (total 22)
BigByte is one byte in bit.Ints
BigEByte is 1,000 SI p bytes in big.Ints
BigEiByte is 1,024 p bytes in bit.Ints
BigGByte is 1,000 SI m bytes in big.Ints
BigGiByte is 1,024 m bytes in bit.Ints
BigKByte is 1,000 SI bytes in big.Ints
BigKiByte is 1,024 bytes in bit.Ints
BigMByte is 1,000 SI k bytes in big.Ints
BigMiByte is 1,024 k bytes in bit.Ints
BigPByte is 1,000 SI t bytes in big.Ints
BigPiByte is 1,024 t bytes in bit.Ints
BigQByte is 1,000 SI r bytes in big.Ints
BigQiByte is 1,024 r bytes in bit.Ints
BigRByte is 1,000 SI y bytes in big.Ints
BigRiByte is 1,024 y bytes in bit.Ints
BigSIByte is one SI byte in big.Ints
BigTByte is 1,000 SI g bytes in big.Ints
BigTiByte is 1,024 g bytes in bit.Ints
BigYByte is 1,000 SI z bytes in big.Ints
BigYiByte is 1,024 z bytes in bit.Ints
BigZByte is 1,000 SI e bytes in big.Ints
BigZiByte is 1,024 e bytes in bit.Ints
Package-Level Constants (total 19)
IEC Sizes.
kibis of bits
Seconds-based time units
SI Sizes.
IEC Sizes.
kibis of bits
SI Sizes.
IEC Sizes.
kibis of bits
SI Sizes.
SI Sizes.
IEC Sizes.
kibis of bits
Seconds-based time units
SI Sizes.
IEC Sizes.
kibis of bits
Seconds-based time units
SI Sizes.
IEC Sizes.
kibis of bits
SI Sizes.
IEC Sizes.
kibis of bits
Seconds-based time units
Seconds-based time units
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |