format_val

Stoner.tools.format_val(value: Union[float, int, complex], **kargs: Any) str[source]

Format a number as an SI quantity.

Parameters

value (float) – Value to format

Keyword Arguments
  • fmt (str) –

    Specify the output format, opyions are:
    • ”text” - plain text output

    • ”latex” - latex output

    • ”html” - html entities

  • escape (bool) – Specifies whether to escape the prefix and units for unprintable characters in non text formats (default False)

  • mode (string) – If “float” (default) the number is formatted as is, if “eng” the value and error is converted to the next samllest power of 1000 and the appropriate SI index appended. If mode is “sci” then a scientifc, i.e. mantissa and exponent format is used.

  • units (string) – A suffix providing the units of the value. If si mode is used, then appropriate si prefixes are prepended to the units string. In LaTeX mode, the units string is embedded in mathrm

  • prefix (string) – A prefix string that should be included before the value and error string. in LaTeX mode this is inside the math-mode markers, but not embedded in mathrm.

Returns

(str) – The formatted value.