Module value

Source
Expand description

Represents a float value using its mantissa and unit Prefix in a base.

With base = 1000, 1k = 1000, 1M = 1_000_000, 1m = 0.001, 1µ = 0.000_001, etc.

min (incl.)max (excl.)magnitudeprefix
....-24Prefix::Yocto
....-21Prefix::Zepto
....-18Prefix::Atto
....-15Prefix::Femto
....-12Prefix::Pico
....-9Prefix::Nano
0.000_0010.001-6Prefix::Micro
0.0011-3Prefix::Milli
11_0000Prefix::Unit
10001_000_0003Prefix::Kilo
1_000_0001_000_000_0006Prefix::Mega
....9Prefix::Giga
....12Prefix::Tera
....15Prefix::Peta
....18Prefix::Exa
....21Prefix::Zetta
....24Prefix::Yotta

The base is usually 1000, but can also be 1024 (bibytes).

With base = 1024, 1ki = 1024, 1Mi = 1024 * 1024, etc.

§Example

use std::convert::From;
use si_scale::{base::Base, value::Value, prefix::Prefix};

let actual = Value::from(0.123);
let expected = Value {
    mantissa: 123f64,
    prefix: Prefix::Milli,
    base: Base::B1000,
};
assert_eq!(actual, expected);

Structs§

Value
Defines the representation of the value.