Formatting#

sigmaepsilon.core.formatting.float_to_str_sig(value: float | Iterable[float], *, sig: int | None = 6, atol: float | None = 1e-07) str | Iterable[str][source]#

Returns a string representation of a floating point number, with given significant digits.

Parameters:
  • value (Union[float, Iterable[float]]) – A single value, or an iterable.

  • sig (int, Optional) – Number of significant digits. Default is 6.

  • atol (float, Optional) – Floating point tolerance. Values smaller than this in the absolute sense are treated as zero. Default is 1e-7.

Returns:

String representation of the provided input.

Return type:

Union[str, Iterable[str]]

See also

floatformatter()

Example

Print the value of pi as a string with 4 significant digits:

>>> from sigmaepsilon.core.formatting import float_to_str_sig
>>> import math
>>> float_to_str_sig(math.pi, sig=4)
'3.142'
sigmaepsilon.core.formatting.floatformatter(*, sig: int | None = 6) str[source]#

Returns a formatter, which essantially a string temapate ready to be formatted.

Parameters:

sig (int, Optional) – Number of significant digits. Default is 6.

Returns:

The string to be formatted.

Return type:

string

Example

Print the value of pi as a string with 4 significant digits:

>>> from sigmaepsilon.core.formatting import floatformatter
>>> import math
>>> formatter = floatformatter(sig=4)
>>> formatter.format(math.pi)
'3.142'