format_error

Stoner.tools.format_error(value: Union[float, int, complex], error: Optional[Union[float, int, complex]] = None, **kargs: Any) str[source]

Format answer with the uncertaintly to 1sf and the value to no more sf’s than the uncertainty.

Parameters:
  • value (float) – The value to be formatted

  • error (float) – The uncertainty in the value

Keyword Arguments:
  • fmt (str) –

    Specify the output format, options 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 scientific, 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:

String containing the formatted number with the eorr to one s.f. and value to no more d.p. than the error.