int/long bug in locale?

T

tkpmep

To pretty up some numbers stored as strings, I used locale to format
them with commas. I then found the following error:
'English_United States.1252'

Traceback (most recent call last):
File "<pyshell#28>", line 1, in <module>
locale.format('%d', float('2244012500.0000'), grouping = True)
File "C:\Python25\lib\locale.py", line 145, in format
formatted = percent % value
TypeError: int argument required

However, if the number is <= 2**31-1, it works just fine:'224,401,250'

Interestingly, if I first convert the floats to ints, , the function
works just fine, even if the numbers exceed 2**31-1:'2,244,012,500'

Is there an int/long related bug lurking in locale?

Sincerely

Thomas Philips
 
N

Neil Cerutti

'English_United States.1252'


Traceback (most recent call last):
File "<pyshell#28>", line 1, in <module>
locale.format('%d', float('2244012500.0000'), grouping = True)
File "C:\Python25\lib\locale.py", line 145, in format
formatted = percent % value
TypeError: int argument required

However, if the number is <= 2**31-1, it works just fine:
'224,401,250'

Interestingly, if I first convert the floats to ints, , the function
works just fine, even if the numbers exceed 2**31-1:
'2,244,012,500'

Is there an int/long related bug lurking in locale?

If it is a bug, it is not in the locale code.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: int argument required

The documentation for the string formating operation doesn't
specify what happens when you convert a non-int with specifier
'%d'. In defense of your code, there's also no explicit
requirement to do that.

http://docs.python.org/lib/typesseq-strings.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,229
Latest member
GloryAngul

Latest Threads

Top