Commit 4242399c authored by Vincent Le gallic's avatar Vincent Le gallic

[ajaj.py, forms.py] On utilise round() avant int() pour éviter les erreurs d'arrondis

Oui, parce que sinon, quand on demande à créditer 0.29, en fait on crédite 0.28.

Merci http://stackoverflow.com/questions/5997027/python-rounding-error-with-float-numbers
parent fa16361b
......@@ -226,7 +226,7 @@ def do_transfert(request):
return HttpResponse(json.dumps({"retcode" : 1112, "msg" : None, "errmsg" : "Transfert impossible : pas d'émetteurs."}))
if destinataires == []:
return HttpResponse(json.dumps({"retcode" : 1113, "msg" : None, "errmsg" : "Transfert impossible : pas de destinataires."}))
montant = int(montant * 100)
montant = int(round(montant * 100))
paquet = ["transferts", [emetteurs, destinataires, montant, commentaire]]
sock.write(json.dumps(paquet))
out = nk.full_read(sock)
......
......@@ -87,7 +87,7 @@ class ReadhesionForm(forms.Form):
"""des valeurs par défaut"""
out = forms.Form.clean(self)
if out.has_key("on_note") and type(out["on_note"]) == float:
out["on_note"] = int(100 * out["on_note"])
out["on_note"] = int(round(100 * out["on_note"]))
else:
out["on_note"] = 0
if out.has_key("section") and (out["section"] == ""):
......@@ -109,7 +109,7 @@ class InscriptionForm(CompteRelatedForm):
"""des valeurs par défaut"""
out = forms.Form.clean(self)
if out.has_key("on_note") and type(out["on_note"]) == float:
out["on_note"] = int(100 * out["on_note"])
out["on_note"] = int(round(100 * out["on_note"]))
else:
out["on_note"] = 0
if out.has_key("report_period") and (out["report_period"] == None):
......@@ -333,7 +333,7 @@ class BoutonForm(forms.Form):
except:
raise forms.ValidationError(u"Je sais pas comme tu t'es débrouillé pour pas me filer un entier dans le champ destinataire, et je veux pas le savoir.")
try:
out['montant'] = int(100 * out['montant'])
out['montant'] = int(round(100 * out['montant']))
except:
raise forms.ValidationError(u"Précise un montant correct.")
return out
......@@ -358,7 +358,7 @@ class MoneyForm(forms.Form):
"""Les centimes"""
out = forms.Form.clean(self)
if out.has_key("montant") and type(out["montant"]) == float:
out["montant"] = int(100 * out["montant"])
out["montant"] = int(round(100 * out["montant"]))
else:
out["montant"] = 0
return out
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment