[Tutor] Help converting strings to numbers

Ignacio Vazquez-Abrams ignacio@openservices.net
Tue, 28 Aug 2001 11:30:12 -0400 (EDT)


On Tue, 28 Aug 2001, dman wrote:

> On Tue, Aug 28, 2001 at 11:36:25AM +0200, Charlie Clark wrote:
> | Dear all,
> |
> | I'm getting a whole set of values and putting them in a dictionary like
> | this
> |
> | {'preis': '2.029,00', 'marktpreis':'3.399,00'}
>
> You Europeans just can't do anything right, can you <wink>?
>
> It would certainly be useful if someone wrote a Euro<=>US literal
> float converter and if the float() function could handle both
> notations.  The easiest is probably just to mangle the string to match
> the US notation and then use float() to convert (or strip the decimal
> point and use int()).
>
> -D

Actually, there is such a converter; it's in the locale module. Just set the
locale to something appropriate using locale.setlocale(), then use
locale.atof() to convert it.

-- 
Ignacio Vazquez-Abrams  <ignacio@openservices.net>