Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Precision of double after decimal point

In the lunch break we started debating about the precision of the double value type.

My colleague thinks, it always has 15 places after the decimal point.

In my opinion one can't tell, because IEEE 754 does not make assumptions about this and it depends on where the first 1 is in the binary representation. (i.e. the size of the number before the decimal point counts, too)

How can one make a more qualified statement?

like image 542
Mare Infinitus Avatar asked Aug 23 '12 10:08

Mare Infinitus


1 Answers

As stated by the C# reference, the precision is from 15 to 16 digits (depending on the decimal values represented) before or after the decimal point.

In short, you are right, it depends on the values before and after the decimal point.

For example:

  • 12345678.1234567D //Next digit to the right will get rounded up
  • 1234567.12345678D //Next digit to the right will get rounded up

Full sample at: http://ideone.com/eXvz3

Also, trying to think about double value as fixed decimal values is not a good idea.

like image 123
jorgebg Avatar answered Oct 22 '22 02:10

jorgebg