我的代码如下(在void main中):
float res;
for(int i=0; i<15; i++) {
res = float(i)/15.0;
//...
}
很不幸,在float(i)/15.0
处出现了语法错误。
如果我只写i/15.0
,那么错误是:
wrong operand types no operation '/' exists that takes a left-hand operand of type 'mediump int' and a right operand of type 'const float' (or there is no acceptable conversion)
如果我只尝试使用i/15
,那么结果将是一个整数,但我想得到一个浮点数。
如何将int
强制转换为float
?