pub fn to_rational2(v: Value) -> Result<Rational, String> {
    match v {
        Value::Null => Ok(zero()),
        Value::Numeric(v, ..) => {
            let r = v.value.as_ratio().map_err(|e| e.to_string())?;
            if v.unit.is_percent() {
                Ok(r / 100)
            } else {
                Ok(r)
            }
        }
        v => Err(format!(
            "{} is not a number",
            v.format(Format::introspect())
        )),
    }
}
/// Gets a percentage as a fraction 0 .. 1.
/// If v is not a percentage, keep it as it is.
Gets a percentage as a fraction 0 .. 1.
If v is not a percentage, keep it as it is.
Gets a percentage as a fraction 0 .. 1 . If v is not a percentage keep it as it is .
pub fn to_rational2(v: Value) -> Result<Rational, String> {
    match v {
        Value::Null => Ok(zero()),
        Value::Numeric(v, ..) => {
            let r = v.value.as_ratio().map_err(|e| e.to_string())?;
            if v.unit.is_percent() {
                Ok(r / 100)
            } else {
                Ok(r)
            }
        }
        v => Err(format!(
            "{} is not a number",
            v.format(Format::introspect())
        )),
    }
}
pub fn to_rational2 ( v : Value ) -> Result < Rational , String > { match v { Value :: Null => Ok ( zero ( ) ) , Value :: Numeric ( v , .. ) => { let r = v . value . as_ratio ( ) . map_err ( | e | e . to_string ( ) ) ? ; if v . unit . is_percent ( ) { Ok ( r / 100 ) } else { Ok ( r ) } } v => Err ( format ! ( " " v format ( Format introspect ( ) ) ) ) , } }
Gets a percentage as a fraction 0 .. 1.
Gets a percentage as a fraction 0 .. 1 .
v
Value