Every line of 'python decimal format' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
16 def format_decimal(value): 17 return Decimal(value.quantize(Decimal('.01'), rounding=ROUND_HALF_UP))
171 def format_decimal(value, quantize='.01'): 172 value = Decimal(value).quantize(Decimal(quantize)) 173 return fdc(value, locale=get_locale_name())
114 def decimal2text(value, places=2, 115 int_units=(('', '', ''), 'm'), 116 exp_units=(('', '', ''), 'm')): 117 value = decimal.Decimal(value) 118 q = decimal.Decimal(10) ** -places 119 120 integral, exp = str(value.quantize(q)).split('.') 121 return u'{} {}'.format( 122 num2text(int(integral), int_units), 123 num2text(int(exp), exp_units))
149 def number_format(value, decimal_pos=None, use_l10n=None, force_grouping=False): 150 """ 151 Formats a numeric value using localization settings 152 153 If use_l10n is provided and is not None, that will force the value to 154 be localized (or not), overriding the value of settings.USE_L10N. 155 """ 156 if use_l10n or (use_l10n is None and settings.USE_L10N): 157 lang = get_language() 158 else: 159 lang = None 160 return numberformat.format( 161 value, 162 get_format('DECIMAL_SEPARATOR', lang, use_l10n=use_l10n), 163 decimal_pos, 164 get_format('NUMBER_GROUPING', lang, use_l10n=use_l10n), 165 get_format('THOUSAND_SEPARATOR', lang, use_l10n=use_l10n), 166 force_grouping=force_grouping 167 )