C语言中强制转换float为int

来源:互联网 发布:篮球教学网络课程 编辑:程序博客网 时间:2024/04/30 11:52
最近遇到float 转换为int 的问题,先上个例子:

#include "main.h"
 
int   main() 
    float a = 1.30;
    float b = 1.30;
    int x,y;
    float tmp;
    tmp = (a*100);
    x = (int)tmp;
    y = (int)(b*100);
    cout<<x<<endl;
    cout<<y<<endl;
    return 0;

输出结果为:
130
129


实际项目中的代码:

0 0
原创粉丝点击