Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why does .NET get simple arithmetic wrong?

arithmetic simple wrong
0
10 Posted

Why does .NET get simple arithmetic wrong?

0
10

.NET doesn’t get arithmetic wrong, as such – it just does arithmetic in a different way to how you might expect. For instance, when you write 0.1 in code to be stored in a double variable, the value stored isn’t actually 0.1. It’s as close to 0.1 as can be represented in the double type, but it’s not actually 0.1. This is because the float/double types are binary floating point types, and 0.1 (decimal) can’t be exactly represented in base 2. For more information on this, see my article on .NET floating point types.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.