Logo

Programming-Idioms

History of Idiom 79 > diff from v5 to v6

Edit summary for version 6 by :

Version 5

2015-09-02, 22:47:26

Version 6

2015-09-03, 11:46:07

Idiom #79 Convert integer to floating point number

Declare floating point number y and initialize it with the value of integer x .

Idiom #79 Convert integer to floating point number

Declare floating point number y and initialize it with the value of integer x .

Code
let y = x as f32;
Doc URL
https://doc.rust-lang.org/book/casting-between-types.html
Demo URL
https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%20%20%20%20let%20i%20%3D%205%3B%0A%20%20%20%20let%20f%20%3D%20i%20as%20f64%3B%0A%20%20%20%20%0A%20%20%20%20println!(%22int%20%7B%3A%3F%7D%2C%20float%20%7B%3A%3F%7D%22%2C%20i%2C%20f)%3B%0A%7D%0A&version=stable