w0051977
w0051977

Reputation: 15817

Why are decimal numbers immune to rounding errors?

I do not understand why decimals can represent numbers like 0.1 and floating points cannot. I have read so many articles and questions on this e.g. this one: Difference between decimal, float and double in .NET?

The answerer in the link above states that floating points are base 2 and decimals are base 10. I believe this has something to do with it. However, I have the same confusion as @BKSpurgeon (comment under the answer). Everything is base 2 in the end?

Upvotes: 1

Views: 401

Answers (1)

Bathsheba
Bathsheba

Reputation: 234785

Decimal numbers do indeed appear to be error free from rounding so long as you write them out with a radix of 10. They most certainly are not "base 2 in the end".

IEEE754 floating point numbers are also error free from rounding if you write them out with a radix of 2.

Upvotes: 1

Related Questions