Coerce a Value to f64. - Integer/Float: direct conversion - String: parse as f64 - Bool: `true` → `1.0`, `false` → `0.0` (when `coerce_bool` is true) - Other types: `None`
(v: &Value, coerce_bool: bool)
| 17 | /// - Bool: `true` → `1.0`, `false` → `0.0` (when `coerce_bool` is true) |
| 18 | /// - Other types: `None` |
| 19 | pub fn value_to_f64(v: &Value, coerce_bool: bool) -> Option<f64> { |
| 20 | match v { |
| 21 | Value::Integer(i) => Some(*i as f64), |
| 22 | Value::Float(f) => Some(*f), |
| 23 | Value::String(s) => s.parse::<f64>().ok(), |
| 24 | Value::Bool(b) if coerce_bool => Some(if *b { 1.0 } else { 0.0 }), |
| 25 | Value::Decimal(d) => { |
| 26 | use rust_decimal::prelude::ToPrimitive; |
| 27 | d.to_f64() |
| 28 | } |
| 29 | _ => None, |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | /// Compare two Values with type coercion. |
| 34 | /// |
no test coverage detected