SigFigFormatter¶
- class SigFigFormatter(sigfig=None, zerotrim=None, base=None)[source]¶
Bases:
Formatter
Format numbers by retaining the specified number of significant digits.
- Parameters
sigfig (
float
, default:3
) – The number of significant digits.zerotrim (
bool
, default:rc['format.zerotrim']
) – Whether to trim trailing decimal zeros.base (
float
, default:1
) – The base unit for rounding. For exampleSigFigFormatter(2, base=5)
rounds to the nearest 5 with up to 2 digits (e.g., 87 –> 85, 8.7 –> 8.5).
Methods Summary
__call__
(x[, pos])Convert number to a string.