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

Pierre Dagenais pierre.dagenais at ncf.ca
Sat Jan 18 19:07:00 CET 2014


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, take everything with a grain of salt!
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
> 
Thank you all who responded, for now I'll go with Keith's solution and
keep the locale for next time.
As all the data has one digit after the decimal I can get away with
myInt = int(temp.replace(',',''))
to convert a string representation of a float to an integer. I'll just
need to remember to divide everything by ten once the calculations are
done. 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?
Also, anybody knows the maximum and/or minimum integer python will accept?

Thank you,
PierreD.


More information about the Tutor mailing list