Pretty printer for numbers with units.

Synopsis

Declared in <folly/String.h>

std::string
prettyPrint(
    double val,
    PrettyType type,
    bool addSpace = true);

Description

A pretty‐printer for numbers that appends suffixes of units of the given type. It prints 4 sig‐figs of value with the most appropriate unit.

If `addSpace' is true, we put a space between the units suffix and the value.

Current types are: PRETTY_TIME ‐ s, ms, us, ns, etc. PRETTY_TIME_HMS ‐ h, m, s, ms, us, ns, etc. PRETTY_BYTES_METRIC ‐ kB, MB, GB, etc (goes up by 10ˆ3 = 1000 each time) PRETTY_BYTES ‐ kB, MB, GB, etc (goes up by 2ˆ10 = 1024 each time) PRETTY_BYTES_IEC ‐ KiB, MiB, GiB, etc PRETTY_UNITS_METRIC ‐ k, M, G, etc (goes up by 10ˆ3 = 1000 each time) PRETTY_UNITS_BINARY ‐ k, M, G, etc (goes up by 2ˆ10 = 1024 each time) PRETTY_UNITS_BINARY_IEC ‐ Ki, Mi, Gi, etc PRETTY_SI ‐ full SI metric prefixes from yocto to Yotta http://en.wikipedia.org/wiki/Metric_prefix PRETTY_BITS_METRIC ‐ kb, Mb, Gb, etc (goes up by 10ˆ3 = 1000 each time) Useful for network bandwidth (e.g., 1 Gbps) PRETTY_BITS ‐ alias for PRETTY_BITS_METRIC

Return Value

The pretty‐printed value.

Parameters

Name

Description

val

The value to format.

type

The unit family to use.

addSpace

Whether to insert a space between the value and its unit.

Created with MrDocs