Receiving double value differently
-
I am assigning double like this double i = 3.34; am getting value into i is 3.3399999999999 if i assign double j = 6.24; am getting value intio j is 6.240000000002 any reason?
-
I am assigning double like this double i = 3.34; am getting value into i is 3.3399999999999 if i assign double j = 6.24; am getting value intio j is 6.240000000002 any reason?
-
I am assigning double like this double i = 3.34; am getting value into i is 3.3399999999999 if i assign double j = 6.24; am getting value intio j is 6.240000000002 any reason?
Floating point numbers used by computers can be only rational (have a limited number of digits). When storing irrational numbers, the stored value must be rounded. Numbers are also stored internally with base 2. So not all decimal numbers (base 10) can be represented as identical base 2 numbers (while the decimal number is rational, the converted base 2 number may be irrational). See the section 'Representable numbers, conversion and rounding' in the Floating point[^] Wikipedia article for a more detailed explanation.