sasdata.data_util.formatnum module¶
Format values and uncertainties nicely for printing.
format_uncertainty_pm()
produces the expanded format v +/- err.
format_uncertainty_compact()
produces the compact format v(##),
where the number in parenthesis is the uncertainty in the last two digits of v.
format_uncertainty()
uses the compact format by default, but this
can be changed to use the expanded +/- format by setting
format_uncertainty.compact to False.
The formatted string uses only the number of digits warranted by the uncertainty in the measurement.
If the uncertainty is 0 or not otherwise provided, the simple %g floating point format option is used.
Infinite and indefinite numbers are represented as inf and NaN.
Example:
>>> v,dv = 757.2356,0.01032
>>> print format_uncertainty_pm(v,dv)
757.236 +/- 0.010
>>> print format_uncertainty_compact(v,dv)
757.236(10)
>>> print format_uncertainty(v,dv)
757.236(10)
>>> format_uncertainty.compact = False
>>> print format_uncertainty(v,dv)
757.236 +/- 0.010
UncertaintyFormatter() returns a private formatter with its own formatter.compact flag.
- sasdata.data_util.formatnum.format_uncertainty_compact(value, uncertainty)¶
Given value v and uncertainty dv, return the compact representation v(##), where ## are the first two digits of the uncertainty.
- sasdata.data_util.formatnum.format_uncertainty_pm(value, uncertainty)¶
Given value v and uncertainty dv, return a string v +/- dv.