Changing from integer to float

At first I didn’t even understand what the difference between these two terms was, but after reading about it I got it. An integer is a simple number without a decimal point. In C++ they are always rounded. For example if an answer is 9.79, it would appear as an integer just as 9 even if it should be rounded to 10. This is because in programming numbers round down. On the other hand, floating point numbers are the ones that have decimals.

To convert from an integer to a floating point number this is what you need to do:

int x = 3

float y = float (x);

Un comentario en “Changing from integer to float

Deja un comentario