Skip to main content

parse_si_value

Function parse_si_value 

Source
pub fn parse_si_value<T>(s: &str) -> Result<T>
where T: FromStr, <T as FromStr>::Err: Display,
Expand description

Parse a numeric value with optional SI suffix (k, M, G)

Supports both integer and floating-point values with SI multipliers:

  • k or K: multiply by 1,000 (kilo)
  • M: multiply by 1,000,000 (mega)
  • G: multiply by 1,000,000,000 (giga)

ยงExamples

use desperado::parse_si_value;

assert_eq!(parse_si_value::<u32>("1090M").unwrap(), 1090000000);
assert_eq!(parse_si_value::<u32>("2400k").unwrap(), 2400000);
assert_eq!(parse_si_value::<u32>("1090000000").unwrap(), 1090000000);
assert_eq!(parse_si_value::<f64>("2.4M").unwrap(), 2400000.0);
assert_eq!(parse_si_value::<i64>("1090M").unwrap(), 1090000000);