ccastingfloating-pointinttype-conversion

C convert floating point to int


I'm using C (not C++).

I need to convert a float number into an int. I do not want to round to the the nearest number, I simply want to eliminate what is after the integer part. Something like

4.9 -> 4.9 -> 4

Solution

  • my_var = (int)my_var;
    

    As simple as that. Basically you don't need it if the variable is int.