atof

Data Type Conversion Functions

Converts a string to a floating point value.

double atof( const char *string);

string The string to convert.

atof reads the initial portion of the string only, by stopping at the first non-numerical character.

Return Values

The converted floating point value of the input string. On overflow the result is undefined. If an error occurs, returns 0.0.

Example

The following example converts the initial portion of the string, s, to a float.

double atof( const char *string); 
vuser_init() {
float x;
char *s = "7.2339 by these hilts or I am a villain else";
x = atof(s);

/* The %.2f formatting string limits the output to 2 decimal places */
lr_output_message("%.2f", x);
return 0;
}
Example: Output:
vuser_init.c(11): 7.23