Skip to content
FloatTryFromStr

FloatTryFromStr

Description

Parse a decimal string into a float. Supports an optional sign, decimal point, and scientific exponent.

Usage example (Cross-references)

Usage examples (Cross-references)
    
        temp = StrInitFromCstr(start, token_len);
        if (!FloatTryFromStr(&parsed, temp.data)) {
            StrDeinit(&temp);
            return start;
        }
    
        if (!FloatTryFromStr(&result, text)) {
            LOG_FATAL("Failed to parse f32 conversion result");
        }
        }
    
        if (!FloatTryFromStr(&result, text)) {
            LOG_FATAL("Failed to parse f64 conversion result");
        }
    }
    
    bool FloatTryFromStr(Float *out, const char *text) {
        Float result       = FloatInit();
        Str   digits       = StrInit();
        Float result = FloatInit();
    
        (void)FloatTryFromStr(&result, text);
        return result;
    }
        Float parsed = FloatFromStr("12.3.4");
        Float value  = FloatInit();
        bool  result = !FloatTryFromStr(&value, "12.3.4");
    
        result = result && FloatIsZero(&parsed);
        Float parsed = FloatFromStr(NULL);
        Float value  = FloatInit();
        bool  result = !FloatTryFromStr(&value, NULL);
    
        result = result && FloatIsZero(&parsed);
Last updated on