Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - Incrementing a double value (1.212E+25)

I have a double value that equals 1.212E+25

When I throw it out to text I do myVar.ToString("0000000000000000000000")

The problem is even if I do myVar++ 3 or 4 times the value seems to stay the same.

Why is that?

like image 877
Jon Avatar asked Dec 29 '22 15:12

Jon


1 Answers

That is because the precision of a double is not sufficient. It simply can't hold that many significant digits.

It will not fit into a long, but probably into a Decimal.

But... do you really need this level of precision?

like image 89
SteinNorheim Avatar answered Dec 31 '22 05:12

SteinNorheim