In C, wcstof() converts wide text to float. It belongs to the wide-character tools declared in <wchar.h>.
Use wchar_t for wide characters and prefix wide literals with L, as in L"Hello". The examples below use simple C Programming Tutorial patterns and print wide strings with %ls.
Syntax
The following concrete call shows the argument shape before the formal declaration.
C
wcstof(L"42.5 rest", &end);
Call
What it does
wcstof(L"42.5 rest", &end)
Converts wide text to float in a typical call.
Include <wchar.h>. Add only the supporting headers actually used by your program.
Prepare a practical variation. The data is arranged specifically to detect invalid input.
Parse the numeric prefix.wcstof(L"42.5 rest", &end) converts the usable characters and leaves the stopping position in end.
Notice the safety rule. The example keeps the count, destination capacity, stream state, and terminator requirements visible.
Interpret the output.converted = no confirms the behavior demonstrated by this example.
Frequently Asked Questions
wcstof() converts wide text to float. It is part of the standard wide-character library.
Its parameters are nptr, endptr. nptr: Wide string containing the number to parse. endptr: Receives the first unconverted wide character; pass NULL when it is not needed.
Converted number means the parsed numeric value. 0 / range limit means no conversion or a range error; inspect endptr and errno.
Include <wchar.h> for wcstof(). Include only the supporting headers used by your program, such as <stdio.h> for FILE or <stdarg.h> for va_list.
A returned zero does not by itself prove failure. Use endptr to see whether any characters were consumed, and check errno for range errors.