You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Harry Broeders edited this page Feb 24, 2023
·
1 revision
0.1 + 0.2 = 0.30000000000000004?
Als je in een Python programma floating point getallen gebruikt, dan is het resultaat soms anders dan je zou denken.
Tienden kun je in het tientallig stelsel exact weergeven, maar in het binair stelsel niet.
Getallen worden in een computer binair (als machten van twee) opgeslagen.
B.v. het getal 0.5 is binair 0.1 en het getal 0.25 is binair 0.01.
Als je het decimale getal 0.1 omzet naar binair vind je:
Dat moet dus afgerond worden om in de computer op te kunnen slaan.
Als je dan gaat rekenen met zo'n afgerond getal, dan is het resultaat niet meer exact correct.
Met de Python-functie round kun je een getal afronden op een bepaald aantal decimalen.