MCPcopy
hub / github.com/django/django / format_number

Function format_number

django/db/backends/utils.py:315–332  ·  view source on GitHub ↗

Format a number into a string with the requisite number of digits and decimal places.

(value, max_digits, decimal_places)

Source from the content-addressed store, hash-verified

313
314
315def 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
335def strip_quotes(table_name):

Callers 1

equalMethod · 0.90

Calls 2

copyMethod · 0.45
formatMethod · 0.45

Tested by 1

equalMethod · 0.72