Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert i32 into f32

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;

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to use @intToFloat function. Like this:

const result = @intToFloat(f32, partial) / @intToFloat(f32, total);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading