wcstod() function in C/C++
The wcstod() function converts the wide string as a double. This function interprets the contents of a wide string as a floating point number. If endString is not a null pointer, the function also sets the value of endString to point to the first character after the number.
Syntax:
double wcstod( const wchar_t* str, wchar_t** str_end )
Parameters: The function accepts two mandatory parameters which are described below:
- string: specifies the string which begins with the representation of a floating-point number
- endString: specifies the pointer to a wide character
Return value: The function returns two value as below:
- On success, the function returns the converted floating point number as a value of type double.
- If no valid conversion could be performed, it returns 0.0 .
- If the correct value is out of the range of representable values for the type, a positive or negative HUGE_VAL is returned, and errno is set to ERANGE.
- If the correct value would cause underflow, the function returns a value whose magnitude is no greater than the smallest normalized positive number (some library implementations may also set errno to ERANGE in this case).
Below programs illustrate the above function:
Program 1 :
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t string[] = L "95.6Geek" ;
wchar_t * endString;
double value = wcstod(string, &endString);
wcout << L "String -> " << string << "\n" ;
wcout << L "Double value -> " << value << "\n" ;
wcout << L "End String is : " << endString << "\n" ;
return 0;
}
|
Output:
String -> 95.6Geek
Double value -> 95.6
End String is : Geek
Program 2 :
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t string[] = L "10.6464" ;
wchar_t * endString;
double value = wcstod(string, &endString);
wcout << L "String -> " << string << "\n" ;
wcout << L "Double value -> " << value << "\n" ;
wcout << L "End String is : " << endString << "\n" ;
return 0;
}
|
Output:
String -> 10.6464
Double value -> 10.6464
End String is :
Program 3 :
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t string[] = L " 99.999Geek" ;
wchar_t * endString;
double value = wcstod(string, &endString);
wcout << L "String -> " << string << "\n" ;
wcout << L "Double value -> " << value << "\n" ;
wcout << L "End String is : " << endString << "\n" ;
return 0;
}
|
Output:
String -> 99.999Geek
Double value -> 99.999
End String is : Geek
Last Updated :
17 Sep, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...