Format a number into a string with the requisite number of digits and decimal places.
(value, max_digits, decimal_places)
| 313 | |
| 314 | |
| 315 | def format_number(value, max_digits, decimal_places): |
| 316 | """ |
| 317 | Format a number into a string with the requisite number of digits and |
| 318 | decimal places. |
| 319 | """ |
| 320 | if value is None: |
| 321 | return None |
| 322 | context = decimal.getcontext().copy() |
| 323 | if max_digits is not None: |
| 324 | context.prec = max_digits |
| 325 | if decimal_places is not None: |
| 326 | value = value.quantize( |
| 327 | decimal.Decimal(1).scaleb(-decimal_places), context=context |
| 328 | ) |
| 329 | else: |
| 330 | context.traps[decimal.Rounded] = 1 |
| 331 | value = context.create_decimal(value) |
| 332 | return "{:f}".format(value) |
| 333 | |
| 334 | |
| 335 | def strip_quotes(table_name): |