View previous topic :: View next topic |
Author |
Message |
zrbz
Joined: 16 Jul 2007 Posts: 2
|
float to int |
Posted: Mon May 26, 2008 1:39 am |
|
|
how do i convert my int value into a float value?
can i do this?
int x;
float y;
x=y; |
|
 |
Ttelmah Guest
|
|
Posted: Mon May 26, 2008 3:30 am |
|
|
Yes.
Why not just try it?.
This is standard C. Implicit type conversion will take place. So x=y will work, as will y=x (the latter will 'lose' the fractional part).
Best Wishes |
|
 |
golf Guest
|
|
Posted: Mon May 26, 2008 3:37 am |
|
|
x is int so, you will lose fractional part;
if you are unsure of the behaviour of the compiler you can make a casting
x = (int)y;
variable y will be integer and assigned to x (compiler makes this by default) |
|
 |
|