Keil Logo

strtod

Summary
#include <stdlib.h>

double strtod (
  const char *string,   /* string to convert */
  char **ptr);          /* ptr to subsequent characters */
Description

The strtod function converts string into a floating-point value. The input string is a sequence of characters that can be interpreted as a floating-point number. Whitespace characters at the beginning of string are skipped.

The value of *ptr is set to point to the first character in string immediately following the converted part of string. If ptr is NULL, no value is assigned to *ptr. If no conversion is possible, *ptr is set to the value of string and the value 0 is returned by the strtod function.

The strtod function requires string to have the following format:

〚{+|-}〛 digits 〚.digits〛 〚{e|E} 〚{+|-}〛 digits

Where

digits May be one or more decimal digits (0-9).
Return Value

The strtod function returns the floating-point value that is produced by interpreting the characters in the string as a floating-point number.

See Also

atof, atoi, atol, strtol, strtoul

Example
#include <stdlib.h>
#include <stdio.h> /* for printf */

void tst_strtod (void) {
  float f;
  char s [] = "1.23 other";
  char *p;

  f = strtod (s, &p);
  printf ("strtod(%s) = %f\n", s, f);

/* p points to " other" */
}
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.