English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C / C ++The strtod() function

The functionstrtod()Used to convert a string to a floating-point number. The string will be converted to a double precision number. It returns the converted number, otherwise returns zero. This is declared in the "stdlib.h" header file.

This isstrtod()C language syntax,

double strtod(const char *string, char **endpointer);

Here,

string-The string to be converted

Terminator-The pointer to the allocated object and its value are set to the next character after the number by the function.

This isstrtod()C language example,

Example

#include <stdio.h>
#include <stdlib.h>
int main () {
   char s[20] = "8.28 is a number";
   char *p;
   double result;
   result = strtod(s, &p);
   printf("The number after conversion of string: %lf", result);
   return(0);
}

Output result

The number after conversion of string : 8.280000

In the above program, a char type array s [20]。This functionstrtod()Used to convert the string to a double.

char s[20] = "8.28 is a number";
char *p;
double result;
result = strtod(s, &p);