Wednesday 18 April 2012

Integer and Float Conversions


There are some rules to convert Floating Point and Integer Values.


  1. If there is an operation between an integer an integer, then the output will also be integer.
  2. If there is an operation between a real number and a real number, then the output will also be a real number.
  3. If there is an operation between an integer and a real number, then the output will be real number. The integer is first promoted to a real number and then the operation is performed. So, the result is real.
Ex. 9 / 2 = 4
       9.0  / 2 = 4.5
       9 / 2.0 = 4.5
       9.0 / 2.0 = 4.5

0 comments: