How To

Why and how does this happen

1

412lop 2023-05-26 12:21

This program adds 0.1 to a value and prints that value, but some times it says something like “2.99997”. So why does this happen.


was8bit 2023-05-26 14:18

Its a decimal rounding issue... common for computers...

If you REALLY need the numbers you expect, stick to whole numbers...


was8bit 2023-05-26 14:21

https://en.wikipedia.org/wiki/Round-off_error


Log in to reply.