Bonjour à tous.
Je souhaite arrondir une valeur à deux décimales près.
Celle valeur étant calculée à partir d'autres.
Voici le code complet :
Dans mon cas il y a 3 valeur en tout à additionner, chacune valant 53,3. Tout se passe bien jusqu'à la dernière ou je passe de 106,6 à 1959.8999999999
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 function calculerMontantTotal(idInput) { var isChecked = document.getElementById("echeancier_" + idInput).checked; var montantTotal = parseFloat(document.getElementById("totalAPayer").value); montantTotal = Math.round(montantTotal*100)/100; var montant = parseFloat(document.getElementById("montant_" + idInput).value); montant = Math.round(montant*100)/100; var cptEcheancier = parseInt(idInput) + 1; if(isChecked) { document.getElementById("totalAPayer").value = montantTotal + montant; toggleEcheancier(cptEcheancier, false, montantTotal); } else { var newMontantTotal = montantTotal - montant; newMontantTotal = Math.round(parseFloat(newMontantTotal)*100)/100; document.getElementById("totalAPayer").value = newMontantTotal; document.getElementById("totalAPayer").value = parseFloat(document.getElementById("totalAPayer").value); document.getElementById("totalAPayer").value = Math.round(document.getElementById("totalAPayer").value*100)/100; toggleEcheancier(cptEcheancier, true, newMontantTotal); } } function toggleEcheancier(idInput, isDisabled, montantTotal) { if(document.getElementById("echeancier_" + idInput) != null) { document.getElementById("echeancier_" + idInput).disabled = isDisabled; if(isDisabled && document.getElementById("echeancier_" + idInput).checked) { document.getElementById("echeancier_" + idInput).checked = false; var montantCourant = parseFloat(document.getElementById("montant_" + idInput).value); montantCourant = Math.round(montantCourant*100)/100; var newMontantTotal = montantTotal - montantCourant; newMontantTotal = Math.round(parseFloat(newMontantTotal)*100)/100; document.getElementById("totalAPayer").value = newMontantTotal; document.getElementById("totalAPayer").value = parseFloat(document.getElementById("totalAPayer").value); document.getElementById("totalAPayer").value = Math.round(document.getElementById("totalAPayer").value*100)/100; var cptEcheancier = parseInt(idInput) + 1; toggleEcheancier(cptEcheancier, isDisabled, newMontantTotal); } }
D'ou cela peut-il venir?
J'espère être assez clair!
Merci d'avance
Partager