Scroll Down to See All▾
abortabsacosasctimeasctime_rasinassertatanatan2atexitatoiatolbsearchbtowccalloccatclosecatgetscatopenceilclearerrclockcoscoshctimectime_rdifftimediverferfcexitexpfabsfclosefdopenfeofferrorfflushfgetcfgetposfgetsfgetwcfgetwsfopenfprintffputcfputwsfreadfreefreopenfrexpfscanffseekfsetposftellfwidefwprintffwritefwscanfgetcgetchargetenvgetwcgetwchargmtimegmtime_rhypotisalnumisalphaisasciiisblankiscntrlisdigitisgraphislowerisprintispunctisspaceisupperiswalnumiswalphaiswblankiswcntrliswctypeiswdigitiswgraphiswloweriswprintiswpunctiswspaceiswupperiswxdigitisxdigitj0j1jnlabsldexpldivlocaleconvlocaltimelocaltime_rloglog10longjmpmallocmblenmbrlenmbrtowcmbsinitmbsrtowcsmbstowcsmbtowcmemchrmemcmpmemcpymemmovememsetmktimemodfnextafternextafterlnexttowardnexttowardlnl_langinfoperrorpowprintfputcputcharputenvputsputwcputwcharqsortquantexpd32quantexpd64quantexpd128quantized32quantized64quantized128samequantumd32raiserandrand_rreallocregcompregerrorregexecregfreeremoverenamerewindscanfsetbufsetjmpsetlocalesetvbufsignalsinsinhsnprintfsprintfsqrtsrandsscanfstrcasecmpstrcatstrchrstrcmpstrcollstrcpystrcspnstrerrorstrfmonstrftimestrlenstrncasecmpstrncatstrncmpstrncpystrpbrkstrptimestrrchrstrspnstrstrstrtodstrtod32strtod64strtod128strtofstrtokstrtok_rstrtolstrtoldstrtoulstrxfrmswprintfswscanfsystemtantanhtimetime64tmpfiletmpnamtoasciitolowertouppertowctranstowlowertowupperungetcungetwcva_argva_copyva_endva_startvfprintfvfscanfvfwprintfvfwscanfvprintfvscanfvsprintfvsnprintfvsscanfvswprintfvswscanfvwprintfvwscanfwcrtombwcscatwcschrwcscmpwcscollwcscpywcscpywcsftimewcslenwcsncatwcsncmpwcsncpywcspbrkwcsptimewcsrchrwcsrtombswcsspnwcsstrwcstodwcstod32wcstod64wcstod128wcstofwcstokwcstolwcstoldwcstombswcstoulwcsxfrmwctobwctombwctranswctypewcwidthwmemchrwmemcmpwmemcpywmemmovewmemsetwprintfwscanfy0y1ynFunction Details : atof
doubleatof(const char * str) ;
Return Type : double
Double-precision floating point (±1.7E±308, ~15 decimal digits)
Read about return values of atof function .
1st Parameter Type : const char *
Pointer to read-only string
1st Parameter
Pointer to a null-terminated string representing a floating-point number
Read more about parameters of atof in parameters section
The atoffunction in C language Converts a string to a floating-point number.
The function discards any whitespace characters until the first non-whitespace character is found, then takes as many characters as possible to form a valid floating-point number representation and converts them to a double value. The rest of the string is ignored.
While in general atof function acts very similar to atoi and atol, there is one crucial difference:the fact that it recognizes and takes care of decimal points and exponents.
While in general atof function acts very similar to atoi and atol, there is one crucial difference:the fact that it recognizes and takes care of decimal points and exponents.
To Summarize the Workflow:
- 1.Takes a string (like "-12.34e5") as input.
- 2.Scans the string, ignoring leading whitespace.
- 3.If the string starts with a + or - sign, it interprets the number as positive or negative accordingly.
- 4.Then processes the digits.
- 5.Handles exponents (if present).
- 6.Recognizes decimal points as part of the number.
- 7.Stops at the first invalid character (like a letter or symbol not part of a valid floating-point number).
- 8.Returns the floating-point value of the processed number (e.g., -1234000.0).
- 9.If the string doesn’t start with a valid number, it returns 0.0.
Read more about return type and value ofatof function in return section.
The atoffunction takes 1
parameter:Converts the initial portion of a string to a `double` value, interpreting the content as a floating-point number.
- •const char * `str`: Pointer to a null-terminated string representing a floating-point number
The atof function return value :
- Returns the converted double value
- If no valid conversion could be performed, it returns 0
- 0
Output
This example demonstrates the basic usage of the `atof` function with different input strings, including a positive number, a negative number with leading whitespace, and an invalid input.