libb.round_digit_string
- round_digit_string(s, places=None)[source]
Round a numeric string to a number of decimal places, digit exact.
A whole value comes back as a plain integer, with leading zeros and a trailing
.0dropped. Any other value comes back in plain notation, with trailing zeros dropped.scomes back unchanged when it is not a finite number, or when the result written out needs more thanROUND_CONTEXT.prec(28) digits. A dropped trailing zero never counts, except while rounding:placesthat pad the value past 28 digits also returns. The caller’s decimal context has no effect.- Parameters:
- Returns:
Rounded numeric string, or
sstripped.- Return type:
Example:
>>> round_digit_string('7283.1234', 3) '7283.123' >>> round_digit_string('7283.1234', None) '7283.1234' >>> round_digit_string('7283', 3) '7283' >>> round_digit_string('9007199254740993') '9007199254740993' >>> round_digit_string('inf') 'inf' >>> round_digit_string('1e400') '1e400'