Skip to content

ZstrToF64

Description

Parse a decimal floating-point value from a null-terminated string. Accepts [+-]?digits(.digits)?([eE][+-]?digits)?. Skips ASCII whitespace before the sign. Not bit-exact: precision-loss is possible on long mantissas. Adequate for JSON / KvConfig numeric values; replaces libc strtod.

Parameters

Name Direction Description
s in Source string.
endptr out If non-NULL, set to the first byte past the last character consumed (matches strtod’s contract).

Success

Returns the parsed value as f64.

Failure

Returns 0.0 when no digits are present.

Usage example (Cross-references)

Usage examples (Cross-references)
        }
    
        parsed = ZstrToF64(value->data, &endptr);
    
        if (!endptr || endptr == value->data || *endptr != '\0') {
        char *end = NULL;
        if (is_flt) {
            num->f = ZstrToF64(ns.data, &end);
        } else {
            num->i = ZstrToI64(ns.data, &end);
    }
    
    f64 ZstrToF64(const char *s, char **endptr) {
        if (!s) {
            if (endptr)
Last updated on