MCPcopy Create free account
hub / github.com/KaisenAmin/c_std / string_to_float

Function string_to_float

string/std_string.c:2464–2481  ·  view source on GitHub ↗

* @brief Converts the content of a String object to a floating-point number. * * This function converts the content of the given String object to a floating-point number (float). * If the String object is NULL or empty, the function logs an error and returns 0.0f. * * @param str The String object to convert. Must not be NULL. * @return The floating-point value of the String object's content,

Source from the content-addressed store, hash-verified

2462 * @return The floating-point value of the String object's content, or 0.0f if the String object is NULL or empty.
2463 */
2464float string_to_float(const String *str) {
2465 STRING_LOG("[string_to_float]: Function start.");
2466
2467 if (str == NULL) {
2468 STRING_LOG("[string_to_float]: Error - Null String object.");
2469 return 0.0f;
2470 }
2471 if (string_empty(str)) {
2472 STRING_LOG("[string_to_float]: Error - Empty string.");
2473 return 0.0f;
2474 }
2475
2476 float result = atof(str->dataStr);
2477 STRING_LOG("[string_to_float]: Converted '%s' to float %f.", str->dataStr, result);
2478 STRING_LOG("[string_to_float]: Function end.");
2479
2480 return result;
2481}
2482
2483
2484/**

Callers

nothing calls this directly

Calls 1

string_emptyFunction · 0.85

Tested by

no test coverage detected