COHERENT manpages
This page displays the COHERENT manpage for strtod() [Convert string to floating-point number].
List of available manpages
Index
strtod() -- General Function (libc) Convert string to floating-point number #include <stdlib.h> double strtod(string, tailptr) char *string; char **tailptr; strtod() converts the number given in string to a double-precision floating-point number and returns its value. It is a more general version of the function atof(). strtod() also stores a pointer to the first character following the number through tailptr, provided tailptr is not NULL. strtod() parses the input string into three portions: beginning, subject sequence, and tail. The beginning consists of zero or more white-space characters that begin the string. The subject sequence is the portion of the input string that strtod() converts into a floating-point number. It consists of an optional sign character, a nonempty sequence of decimal digits optionally including a decimal-point character, and an optional exponent. If present, the exponent consists of either `e' or `E' followed by an optional sign and a nonempty sequence of decimal digits. strtod() reads characters until it encounters either a second decimal-point character or exponent marker, or any other non-numeral. The tail continues from the end of the subject sequence to the null character that ends the string. strtod() ignores the beginning portion of the string. It converts the subject sequence to a double-precision number. Finally, it sets the pointer pointed to by tailptr to the address of the first character of the string's tail. strtod() returns the double generated from the subject sequence. If no subject sequence could be recognized, it returns zero and stores the initial value of string through tailptr. If the number represented by the subject sequence is too large or too small to fit into a double, then strtod() sets the global constant errno to ERANGE and returns HUGE_VAL or zero, respectively. If, however, the number given in the subject sequence has more digits to the right of the decimal point than can be encoded within an IEEE double (which has a fraction of 53 bits), strtod trims the excess digits before it converts the string. Example The following gives an example for strtod(). #include <stdlib.h> main() { static char st[] = " 123.4 567.8"; char *head, *tail; for (head = st;; head = tail) { double amt = strtod(head, &tail); /* No token found is end of string */ if (head == tail) break; printf("%f\n", amt); } exit(EXIT_SUCCESS); } See Also atof(), double, errno, libc, limits.h, stdlib.h, strtol(), strtoul() ANSI Standard, §7.10.1.4 Notes strtod() ignores initial white space in the string pointed to by string; white space is defined as being all characters so recognized by the function isspace().