Module malachite_base::num::conversion::string::from_sci_string
source · Expand description
FromSciString
, a trait for converting strings, possibly using
scientific notation, to numbers.
§from_sci_string
use malachite_base::num::conversion::traits::FromSciString;
assert_eq!(u8::from_sci_string("123"), Some(123));
assert_eq!(u8::from_sci_string("123.5"), Some(124));
assert_eq!(u8::from_sci_string("256"), None);
assert_eq!(u64::from_sci_string("1.23e10"), Some(12300000000));
§from_sci_string_with_options
use malachite_base::num::conversion::string::options::FromSciStringOptions;
use malachite_base::num::conversion::traits::FromSciString;
use malachite_base::rounding_modes::RoundingMode::*;
let mut options = FromSciStringOptions::default();
assert_eq!(
u8::from_sci_string_with_options("123.5", options),
Some(124)
);
options.set_rounding_mode(Floor);
assert_eq!(
u8::from_sci_string_with_options("123.5", options),
Some(123)
);
options = FromSciStringOptions::default();
options.set_base(16);
assert_eq!(u8::from_sci_string_with_options("ff", options), Some(255));