Format a numeric value using localization settings. If use_l10n is provided and is not None, it forces the value to be localized (or not), otherwise it's always localized.
(value, decimal_pos=None, use_l10n=None, force_grouping=False)
| 170 | |
| 171 | |
| 172 | def number_format(value, decimal_pos=None, use_l10n=None, force_grouping=False): |
| 173 | """ |
| 174 | Format a numeric value using localization settings. |
| 175 | |
| 176 | If use_l10n is provided and is not None, it forces the value to |
| 177 | be localized (or not), otherwise it's always localized. |
| 178 | """ |
| 179 | if use_l10n is None: |
| 180 | use_l10n = True |
| 181 | lang = get_language() if use_l10n else None |
| 182 | return numberformat.format( |
| 183 | value, |
| 184 | get_format("DECIMAL_SEPARATOR", lang, use_l10n=use_l10n), |
| 185 | decimal_pos, |
| 186 | get_format("NUMBER_GROUPING", lang, use_l10n=use_l10n), |
| 187 | get_format("THOUSAND_SEPARATOR", lang, use_l10n=use_l10n), |
| 188 | force_grouping=force_grouping, |
| 189 | use_l10n=use_l10n, |
| 190 | ) |
| 191 | |
| 192 | |
| 193 | def localize(value, use_l10n=None): |
no test coverage detected