C convert floating point to int

匿名 (未验证) 提交于 2019-12-03 03:10:03

问题:

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

回答1:

my_var = (int)my_var; 

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



回答2:

Use in C

int C = var_in_float; 

They will convert implicit

Thank you



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!