Can't parse String from stdin to floating-point - Rust

前端 未结 2 1794
孤城傲影
孤城傲影 2021-01-21 13:36

When parsing a String type value to a floating-point type value in Rust, everything works fine with
\"let pi: f64 = 3.14\".parse().unwrap();.

However,

2条回答
  •  终归单人心
    2021-01-21 13:58

    As suggested by SCappella the new line needs to be removed. The following will work:

    let user_input: f64 = s.trim().parse().unwrap();
    

提交回复
热议问题