MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / value_to_f64

Function value_to_f64

nodedb-query/src/value_ops.rs:19–31  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

17/// - Bool: `true` → `1.0`, `false` → `0.0` (when `coerce_bool` is true)
18/// - Other types: `None`
19pub 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///

Callers 8

num_argFunction · 0.85
compare_valuesFunction · 0.85
coerced_eqFunction · 0.85
eval_scopeMethod · 0.85
eval_binary_opFunction · 0.85
num_argFunction · 0.85
extract_f64Function · 0.85
extract_f64_valFunction · 0.85

Calls 1

okMethod · 0.45

Tested by

no test coverage detected