On 12/31/2013 12:56 PM, Mark Lawrence wrote:
import locale

# Set to users preferred locale:
locale.setlocale(locale.LC_ALL, '')
# Or a specific locale:
locale.setlocale(locale.LC_NUMERIC, "en_DK.UTF-8")
print(locale.atof("3,14"))


This is a good solution, but be aware that it could impact other parts of your porgram as well, particularly if this is a read in data set from a non-local region. Also, in places where commas are used as decimal points, it's also common to use periods as commas:

>>> print(locale.atof("123.456,14"))
123456.14

Emile





_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to