Friday, July 19, 2013

Fun with Numbers - Primitive Data types in APEX

Did you come across the issue when there can be obvious things we might miss primitive data types in APEX. One example I came across was as below

Double  myVal   = 3 * (10 / 4);

I expected the value to be 7.5 right... wait..
00:06:08.038 (38803000)|USER_DEBUG|[3]|DEBUG|RAJ    :6.0


Next  I changed the value to this..

Double myVal2  = 3 * (10 / 4.00);

00:06:08.038 (38895000)|USER_DEBUG|[4]|DEBUG|RAJ    :7.5

The simple variation on how the primitives are handled by the compiler is important.