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,
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(",",
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
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
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
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!
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
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
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