[英]Convert i32 into f32
How can I convert a i32 into a f32 in Zig Language?如何将 i32 转换为 Zig 语言中的 f32?
I want to count appearances of values in a for loop and afterwards get the percentages in a smooth floating number.我想计算 for 循环中值的出现次数,然后以平滑的浮点数获得百分比。
var partial : i32 = 0;
var total : i32 = 2000;
for (arr[0..total]) |value| {
if(value < 200) inCircle = inCircle + 1;
}
const result = partial / total;
You need to use @intToFloat
function. Like this:您需要使用
@intToFloat
function。像这样:
const result = @intToFloat(f32, partial) / @intToFloat(f32, total);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.