Documentation
¶
Overview ¶
Package unitconv implements string conversion functionality for unit prefixes such as those from the SI and IEC standards. It is catered towards printing of values for human consumption. Consequently it prints of reasonable precision proportional to the magnitude of the value itself.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatDuration ¶
FormatDuration formats the duration with precision proportional to the magnitude of the duration. This differs from the time.Duration.String format in that it additionally supports year ('y') and day ('d') units, where a year is exactly 365.25 days and a day is exactly 24 hours.
Examples:
12ns 5.12μs 832μs 8.14ms 512ms 1.3s 58s 5m23s 4h23m 4d16h 17y53d
func FormatIEC ¶
FormatIEC formats the number using a binary prefix (e.g. Ki, Mi, Gi, etc.) combined with the provided unit suffix. Any leading spaces in the unitSuffix are moved before the metric prefix.
Example:
FormatIEC(123, "B") => "123B" FormatIEC(12345678, " B/s") => "11.77 MiB/s"
Exact precision and width of the output may change in the future.
func FormatSI ¶
FormatSI formats the number using a metric prefix (e.g. k, M, G, etc.) combined with the provided unit suffix. Any leading spaces in the unitSuffix are moved before the metric prefix.
Example:
FormatSI(123, "P/s") => "123P/s" FormatSI(12345678, " W") => "12.3 MW"
Exact precision and width of the output may change in the future.
Types ¶
This section is empty.