本文介绍了C将浮点数转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 C (不是C ++)。我需要将浮点数转换为
INT
。我不想四舍五入到最接近的数字,我只是想消除整数部分之后的东西。就像 4.9 - > 4 - > 4
解决方案
my_var =(int)my_var;
这么简单。
基本上,如果变量是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 -> 4
解决方案
my_var = (int)my_var;
As simple as that.Basically you don't need it if the variable is int.
这篇关于C将浮点数转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!