github.com/tunabay/go-infounit (go): Package infounit provides information unit data types that can be formatted into human-readable string representations. The following three data types are implemented:  These types can be formatted into and scanned from human-readable string representations with both SI and binary prefixes using the standard Printf and Scanf family functions in the package fmt.  Each data type also provides methods such as scanning and unit conversion.  ByteCount represents a number of bytes. It is a suitable type for storing file size, transferred data amount, etc. It is internally uint64. Thus new values can be declared in the usual ways and it is possible to convert between ByteCount and uint64 values.  The common values for both SI and binary prefixes are defined as constants. Values with units can be declared by multiplying by them in a similar way to the Duration in the package time:  Unit conversion is also possible by division:  See the Constants section below for the complete list of defined constants.  ByteCount values can be flexibly formatted using the standard Printf family functions in the package fmt, fmt.Printf, fmt.Fprintf, fmt.Sprintf, fmt.Errorf, and functions deriverd from them.  For ByteCount type, two custom 'verbs' are implemented:  By using these, the same value can be formatted with both SI and binary prefixes:  They also support flags ' '(space) and '#', width and precision, so the format can be changed flexibly:  A ' '(space) flag puts a spece between digits and the unit. A '#' flag uses an alternative long unit name. See the Format method documentation bellow for details on all supported verbs and flags.  ByteCount type also supports the standard Scanf family functions in the package fmt, fmt.Scanf, fmt.Fscanf(), and fmt.Sscanf(). Human-readable string representations with SI and binary prefixes can be "scanned" as ByteCount values.  Note that unlike Printf, the %s verb properly scans units with both SI and binary prefixes. So it is usually fine to use only the %s verb to scan. The %S verb treats the SI prefix representation as binary prefixes. See the Scan method documentation bellow for details.  BitCount represents a number of bits. It is internally uint64. Functions and usage are almost the same as ByteCount, except that it represents a number of bits instead of bytes.  BitRate represents a number of bits that are transferred or processed per unit of time. It is a suitable type for storing data transfer speed, processing speed, etc. It is internally float64.
Keywords: binary-prefix|bit-count|bit-rate|byte-count|go|go-package|golang|human-readable|printf|scanf|si-prefix|unit