Module: lopaths.sig_fig_rounding

Retrieved on 08.07.2019 from https://github.com/odysseus9672/SELPythonLibs/blob/master/SigFigRounding.py

@author: odysseus9672

Functions:

FormatValToSigFigs(x, sigfigs[, sciformat])

Rounds the value(s) in x to the number of significant figures in sigfigs.

FormatValWithUncRounding(x, unc[, …])

Rounds unc (the uncertainty) to the number of significant figures in uncsigfigs.

RoundToSigFigs_decim(x, sigfigs)

Rounds the value(s) in x to the number of significant figures in sigfigs.

RoundToSigFigs_fp(x, sigfigs[, upper])

Rounds the value(s) in x to the number of significant figures in sigfigs.

SetDecimalPrecision(precision)

ValueWithUncsRounding(x, uncs[, uncsigfigs])

Rounds all of the values in uncs (the uncertainties) to the number of significant figures in uncsigfigs.

FormatValToSigFigs(x, sigfigs, sciformat=True)[source]

Rounds the value(s) in x to the number of significant figures in sigfigs. Return value is a string. The keyword argument sciformat will force scientific notation if true. Restrictions: sigfigs must be an integer type and store a positive value. x must be a real value or an array like object containing only real values.

FormatValWithUncRounding(x, unc, uncsigfigs=1, sciformat=True)[source]

Rounds unc (the uncertainty) to the number of significant figures in uncsigfigs. Then rounds the value in x to the same decimal pace as the value in unc. Uses the decimal package for maximal accuracy. Return value is a tuple containing two strings. The keyword argument sciformat will force scientific notation if true. Restrictions: - uncsigfigs must be a positive integer. - x must be a real value or floating point. - unc must be a real value or floating point

RoundToSigFigs_decim(x, sigfigs)[source]

Rounds the value(s) in x to the number of significant figures in sigfigs. Uses logarithm function and Python’s Decimal library, so will be slower. Restrictions: sigfigs must be an integer type and store a positive value. x must be a Python Decimal value. No arrays accepted.

RoundToSigFigs_fp(x, sigfigs, upper=False)[source]

Rounds the value(s) in x to the number of significant figures in sigfigs. Return value has the same type as x. Restrictions: sigfigs must be an integer type and store a positive value. x must be a real value or an array like object containing only real values.

SetDecimalPrecision(precision)[source]
ValueWithUncsRounding(x, uncs, uncsigfigs=1)[source]

Rounds all of the values in uncs (the uncertainties) to the number of significant figures in uncsigfigs. Then rounds the values in x to the same decimal pace as the values in uncs. Return value is a two element tuple each element of which has the same type as x and uncs, respectively. Restrictions: - uncsigfigs must be a positive integer.

  • x must be a real value or an array like object containing only real values.

  • uncs must be a real value or an array like object containing only real values.