Re: [Tutor] ValueError: could not convert string to float: '13,2'

2014-01-20 Thread Pierre Dagenais
Not very elegant, but it'll work. I don't suppose there is a >> function for determining the number of digits after the decimal, is it? > > It looks like you are trying to avoid rounding errors in decimal arithmetic. > You might be interested in Python's decimal.Decimal type then. That's right,

Re: [Tutor] ValueError: could not convert string to float: '13,2'

2014-01-19 Thread Peter Otten
Pierre Dagenais wrote: > > > On 13-12-31 04:09 PM, Keith Winston wrote: >> Hi PierreD, I think if you iterate over your strings with something like >> this, it will do what you want, if I understand correctly (snum is your >> string number, like "123,321"): >> >> fnum = float(snum.replace(",",

Re: [Tutor] ValueError: could not convert string to float: '13,2'

2014-01-18 Thread Pierre Dagenais
On 13-12-31 04:09 PM, Keith Winston wrote: > Hi PierreD, I think if you iterate over your strings with something like > this, it will do what you want, if I understand correctly (snum is your > string number, like "123,321"): > > fnum = float(snum.replace(",", ".") > > keith: rank beginner, tak

Re: [Tutor] ValueError: could not convert string to float: '13,2'

2014-01-03 Thread eryksun
On Fri, Jan 3, 2014 at 11:53 AM, emile wrote: > 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

Re: [Tutor] ValueError: could not convert string to float: '13,2'

2014-01-03 Thread emile
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 othe

Re: [Tutor] ValueError: could not convert string to float: '13,2'

2013-12-31 Thread Keith Winston
Hi PierreD, I think if you iterate over your strings with something like this, it will do what you want, if I understand correctly (snum is your string number, like "123,321"): fnum = float(snum.replace(",", ".") keith: rank beginner, take everything with a grain of salt!

Re: [Tutor] ValueError: could not convert string to float: '13,2'

2013-12-31 Thread Keith Winston
Playing with this, a list comprehension is perfect: fnumlist = [float(num.replace(",", ".")) for num in snumlist] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] ValueError: could not convert string to float: '13,2'

2013-12-31 Thread Mark Lawrence
On 31/12/2013 13:53, Pierre Dagenais wrote: Hi, I'm trying to convert a list of strings to float. Unfortunately the numbers are written with a decimal comma instead of a decimal point. What is the best way to replace these commas with decimal points? Do I need to write a function that will itera

[Tutor] ValueError: could not convert string to float: '13,2'

2013-12-31 Thread Pierre Dagenais
Hi, I'm trying to convert a list of strings to float. Unfortunately the numbers are written with a decimal comma instead of a decimal point. What is the best way to replace these commas with decimal points? Do I need to write a function that will iterate over every alphanumeric, replace the comma