|
|
@ -10,6 +10,7 @@ from . import compat |
|
|
|
from .i18n import gettext as _ |
|
|
|
from .i18n import gettext_noop as N_ |
|
|
|
from .i18n import pgettext as P_ |
|
|
|
from .i18n import thousands_separator |
|
|
|
|
|
|
|
|
|
|
|
def ordinal(value): |
|
|
@ -99,9 +100,10 @@ def intcomma(value, ndigits=None): |
|
|
|
Returns: |
|
|
|
str: string containing commas every three digits. |
|
|
|
""" |
|
|
|
sep = thousands_separator() |
|
|
|
try: |
|
|
|
if isinstance(value, compat.string_types): |
|
|
|
float(value.replace(",", "")) |
|
|
|
float(value.replace(sep, "")) |
|
|
|
else: |
|
|
|
float(value) |
|
|
|
except (TypeError, ValueError): |
|
|
@ -112,7 +114,7 @@ def intcomma(value, ndigits=None): |
|
|
|
else: |
|
|
|
orig = str(value) |
|
|
|
|
|
|
|
new = re.sub(r"^(-?\d+)(\d{3})", r"\g<1>,\g<2>", orig) |
|
|
|
new = re.sub(r"^(-?\d+)(\d{3})", r"\g<1>%s\g<2>" % sep, orig) |
|
|
|
if orig == new: |
|
|
|
return new |
|
|
|
else: |
|
|
|