Pages : 1
#1 Le 20/09/2010, à 12:02
- AnsuzPeorth
Petit problème calcul float python
Bjr,
Un petit soucis assez embêtant !
>>> l = [0.16, 0.20]
>>> l
[0.16, 0.20000000000000001]
>>> l[0]+l[1]
0.35999999999999999
Je devrait avoir 0.36 !
Dans mon cas, les chiffres sont du texte, donc:
>>> l = [ '0.16','0.20']
>>> float(l[0])+float(l[1])
0.35999999999999999
Si qql'un a la solution, merci.
Interface graphique pour bash, python ou autre: glade2script
Support Tchat: http://chat.jabberfr.org/muckl_int/inde … ade2script (Hors ligne)
Hors ligne
#2 Le 20/09/2010, à 12:13
- HP
Re : Petit problème calcul float python
>>> from decimal import Decimal
>>> l = ['0.16', '0.20']
>>> Decimal(l[0]) + Decimal(l[1])
Decimal('0.36')
Dernière modification par HP (Le 20/09/2010, à 12:16)
cat /dev/urandom >/dev/null 2>&1 #github
Hors ligne
#3 Le 20/09/2010, à 12:27
- AnsuzPeorth
Re : Petit problème calcul float python
J'avais jamais été voir du coté de ce module.
Merci !
Interface graphique pour bash, python ou autre: glade2script
Support Tchat: http://chat.jabberfr.org/muckl_int/inde … ade2script (Hors ligne)
Hors ligne