Function read_f64

Source
pub fn read_f64(msg: Option<&str>, err_msg: Option<&str>) -> f64
Expand description

§ARGUMENTS

‘msg’ (Option<&str>) - an optional message which will be printed at the same line as the input prompt. Must be set to Some(“…”) or None.

‘err_msg’ (Option<&str>) - an optional error message which will be printed if the user inputs an invalid value. Must be set to Some(“…”) or None.

§DESCRIPTION

Prompts the user to type a real number with double precision (f64) which will then be returned. Both ‘.’ and ‘,’ are accepted as separators for the decimal part (Ex: 12.3 and 45,67). If the user writes an invalid value, they will be prompted to try again.

Provides an information message on the same line as the prompt if Some(“…”) is provided, and just the prompt if None is provided.

If err_msg is set to None, a default message will be shown.

§RETURNS

A floating point value of type f64 provided by the user.

§EXAMPLES

use quick_input::read_f64;
let user_f64_with_msg = read_f64(Some("Please input a number with decimals: "), Some("Please input a valid number."));

let user_f64: f64 = read_f64(None, None);