issue79:tutoriel_-_python_49
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue79:tutoriel_-_python_49 [2014/03/16 21:14] – [7] fredphil91 | issue79:tutoriel_-_python_49 [2014/03/29 17:57] (Version actuelle) – [8] auntiee | ||
---|---|---|---|
Ligne 10: | Ligne 10: | ||
WHAT? | WHAT? | ||
- | Alors que je travaillais | + | Alors que j' |
Prenez par exemple un simple calcul : 1.1 + 2.2 | Prenez par exemple un simple calcul : 1.1 + 2.2 | ||
Ligne 33: | Ligne 33: | ||
1.1+2.2 | 1.1+2.2 | ||
- | Et la réponse est : 3.3000000000000003 Vous regardez fixement l' | + | Et la réponse est : 3.3000000000000003 Vous regardez fixement l' |
2.2+3.3 | 2.2+3.3 | ||
- | 5.5 Maintenant, vous êtes encore plus confus et vous vous dites « D' | + | 5.5 Maintenant, vous êtes encore plus confus et vous vous dites : « D' |
====== 3 ====== | ====== 3 ====== | ||
Ligne 77: | Ligne 77: | ||
Decimal(1/ | Decimal(1/ | ||
- | Decimal(' | + | Decimal(' |
Decimal(1.1+2.2) | Decimal(1.1+2.2) | ||
Ligne 88: | Ligne 88: | ||
So what do we do about it? Well, the quick answer is that you probably can live with it for 90% of the things we have to do out there in the real world – by using the round() method. While you have to decide on the number of decimal points that you must have in your world to carry the precision that you need, for the most part, this will be an acceptable workaround.** | So what do we do about it? Well, the quick answer is that you probably can live with it for 90% of the things we have to do out there in the real world – by using the round() method. While you have to decide on the number of decimal points that you must have in your world to carry the precision that you need, for the most part, this will be an acceptable workaround.** | ||
- | C'est ce qu'on appelle | + | C'est ce qu'on appelle |
- | Alors, que faisons-nous avec ça ? Eh bien, la réponse rapide est que vous pouvez probablement vivre avec dans 90% des cas que nous avons à traiter dans le monde réel - en utilisant la méthode round(). Vous devrez décider le nombre de décimales dont vous avez besoin dans votre monde pour avoir la précision dont vous avez besoin, mais pour la plupart ce sera une solution acceptable. | + | Alors, que faisons-nous avec ça ? Eh bien, la réponse rapide est que vous pouvez probablement vivre avec dans 90% des cas que nous avons à traiter dans le monde réel - en utilisant la méthode round(). Vous devrez décider le nombre de décimales dont vous avez besoin dans votre monde pour avoir la précision dont vous avez besoin, mais la plupart |
====== 6 ====== | ====== 6 ====== | ||
Ligne 123: | Ligne 123: | ||
====== 8 ====== | ====== 8 ====== | ||
- | 3.1416 All that sounds good until you run into a value like 2.675 and try to round it to 2 decimal places. The assumption (since it is exactly halfway between 2.67 and 2.68) is that the returned value will be 2.68. Try it. | + | **3.1416 All that sounds good until you run into a value like 2.675 and try to round it to 2 decimal places. The assumption (since it is exactly halfway between 2.67 and 2.68) is that the returned value will be 2.68. Try it. |
round(2.675, | round(2.675, | ||
Ligne 131: | Ligne 131: | ||
The bottom line here is when trying to compare floating-point numbers, be aware that some things just don’t translate well. | The bottom line here is when trying to compare floating-point numbers, be aware that some things just don’t translate well. | ||
- | See you next time! | + | See you next time!** |
+ | |||
+ | 3,1416 Tout cela fonctionne parfaitement, | ||
+ | |||
+ | round(2.675, | ||
+ | |||
+ | 2.67 Cela pourrait poser un problème. Et on revient à la question initiale dont nous parlions. Avec la conversion en un nombre binaire à virgule flottante de 53 bits de long, le nombre devient : 2, | ||
+ | |||
+ | L' | ||
+ | |||
+ | Rendez-vous la prochaine fois ! | ||
issue79/tutoriel_-_python_49.1395000886.txt.gz · Dernière modification : 2014/03/16 21:14 de fredphil91