The strtod() is a builtin function in C and C++ STL which interprets the contents of the string as a floating point number and return its value as a double.
It sets a pointer to point to the first character after the last valid character of the string, only if there is any, otherwise it sets the pointer to null.
double strtod(str, &end)
str: It specifies the string which has the representation of a floating point number.
end: It is specified the parameter that refers to an already allocated object of type char*.
Return Value: It returns a double value, which is converted from a string, and 0, if no valid conversion can be performed.
Below programs illustrate the above function:
number = 11.03e 0mn double = 11.03 end string = e 0mn
number= 4.06 double= 4.06 null
strtod() function with exponents and hexadecimals
str = -89.04e-3win gfg double = -0.08904 end string = win gfg str = 1998gupta.1204ishwar double = 1998 end string = gupta.1204ishwar
Infinity to double = inf end string = Infpqrs to double = inf end string = pqrs NaN11x to double = nan end string = 11x
strtod() function with leading whitespace
99.99 to double = 19.99 end string = xyz1.80 to double = 0 end string = xyz1.80
- Function Overloading vs Function Overriding in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- exp() function C++
- log() function in C++
- arc function in C
- div() function in C++
- fma() function in C++
- wcstombs() function in C++ STL
- iswdigit() function in C/C++
- unordered_multiset end() function in C++ STL
- strrev() function in C
- iswspace() function in C/C++
- array get() function in C++ STL
- array at() function in C++ STL
- atexit() function in C/C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.