This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: error converting locale number to decimal
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: facundobatista Nosy List: facundobatista, georg.brandl, oswaldohm, quiver
Priority: normal Keywords:

Created on 2005-08-30 09:16 by oswaldohm, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg26148 - (view) Author: oswaldo (oswaldohm) Date: 2005-08-30 09:16
Hello,

When I try con convert a locale formated number to
decimal y generate an error:

>>> import locale
>>> import decimal
>>> locale.setlocale(locale.LC_ALL, "sp")
'Spanish_Spain.1252'
>>> n = locale.format("%f", 123456.78, 1)
>>> n
'123.456,780000'
>>> d = decimal.Decimal(n)
  File "<console>", line 1, in ?
  File "C:\Python24\Lib\decimal.py", line 571, in __new__
    self._sign, self._int, self._exp =
context._raise_error(ConversionSyntax)
  File "C:\Python24\Lib\decimal.py", line 2266, in
_raise_error
    raise error, explanation
''' decimal.InvalidOperation :  '''
>>> 

Thanks
msg26149 - (view) Author: George Yoshida (quiver) (Python committer) Date: 2005-08-30 10:48
Logged In: YES 
user_id=671362

I guess this is because '123.456,780000' does not conform to 
the decimal numeric string syntax :
  decimal-part   ::=  digits '.' [digits] | ['.'] digits

see : http://docs.python.org/lib/node177.html

It does not seem to be a bug to me.
msg26150 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-08-30 19:23
Logged In: YES 
user_id=1188172

Correct. Decimal cannot guess which locale your number
string might be in, so please format the float using regular
string formatting and not locale.format.
History
Date User Action Args
2022-04-11 14:56:12adminsetgithub: 42321
2005-08-30 09:16:28oswaldohmcreate