1313from .i18n import _ngettext
1414from .i18n import _ngettext_noop as NS_
1515from .i18n import _pgettext as P_
16- from .i18n import thousands_separator
16+ from .i18n import decimal_separator , thousands_separator
1717
1818if TYPE_CHECKING :
1919 if sys .version_info >= (3 , 10 ):
@@ -130,10 +130,11 @@ def intcomma(value: NumberOrString, ndigits: int | None = None) -> str:
130130 Returns:
131131 str: String containing commas every three digits.
132132 """
133- sep = thousands_separator ()
133+ thousands_sep = thousands_separator ()
134+ decimal_sep = decimal_separator ()
134135 try :
135136 if isinstance (value , str ):
136- value = value .replace (sep , "" )
137+ value = value .replace (thousands_sep , "" ). replace ( decimal_sep , ". " )
137138 if "." in value :
138139 value = float (value )
139140 else :
@@ -147,8 +148,9 @@ def intcomma(value: NumberOrString, ndigits: int | None = None) -> str:
147148 orig = "{0:.{1}f}" .format (value , ndigits )
148149 else :
149150 orig = str (value )
151+ orig = orig .replace ("." , decimal_sep )
150152 while True :
151- new = re .sub (r"^(-?\d+)(\d{3})" , rf"\g<1>{ sep } \g<2>" , orig )
153+ new = re .sub (r"^(-?\d+)(\d{3})" , rf"\g<1>{ thousands_sep } \g<2>" , orig )
152154 if orig == new :
153155 return new
154156 orig = new
0 commit comments