How can I convert a i32 into a f32 in Zig Language?
I want to count appearances of values in a for loop and afterwards get the percentages in a smooth floating number.
var partial : i32 = 0;
var total : i32 = 2000;
for (arr[0..total]) |value| {
if(value < 200) inCircle = inCircle + 1;
}
const result = partial / total;
>Solution :
You need to use @intToFloat function. Like this:
const result = @intToFloat(f32, partial) / @intToFloat(f32, total);