Home »
Rust »
Rust Programs
Rust program to convert an integer number into a float number
Rust | Convert int to float: Given an integer number, we have to convert it into float.
Last Updated : October 07, 2021
Problem Statement
In this program, we will create an integer variable then we will assign the value of the integer variable by converting it into a float variable using the "as" keyword.
Program/Source Code
The source code to convert an integer number into a float number is given below. The given program is compiled and executed successfully.
// Rust program to convert an
// integer number into a float number
fn main()
{
let mut intVar:i32 = 5;
let mut floatVar:f32 = 0.0;
floatVar=intVar as f32;
println!("Number is : {}",floatVar);
}
Output
Number is : 5
Explanation
Here, we created a variable intVar of the i32 type. Then we assigned the value of the intVar variable into the floatVar variable using the as keyword. After that, we printed the result.
Rust Basic Programs »
Advertisement
Advertisement