You are on page 1of 1

What happens if you assign variable declared as

integer to a floating point value?


Anshul Gour

August 28, 2019

Let us take an example. Variable ’i’ declared as integer and its value is
4.999999 as floating point value. As shown in the figure we can see that the
output is 4. Integer is a whole number. Nothing after the decimal point is
stored.

So if you put a floating value into integer- then everything after the
decimal point is lost. When you convert an integer into float, the missing
decimal part is filled with zeros before being stored into the float variable.
For example if we store integer 4 into float variable then the output is
4.000000.

You might also like