Convert float to integer in Rust

后端 未结 3 1351
鱼传尺愫
鱼传尺愫 2021-02-03 19:02
double b = a / 100000;
b = (int) b;
b *= 100000;

How the above C code is converted to Rust? Especially the line #2 that rounds the number.

3条回答
  •  旧巷少年郎
    2021-02-03 19:18

    To cast a float to an integer, you can use as. For example:

    let b = (a / 100000.0) as i64;
    

提交回复
热议问题