_atodbl, _atodbl_l, _atoldbl, _atoldbl_l, _atoflt _atoflt_l

Converts a string to a double (_atodbl), long double (_atoldbl), or float (_atoflt).

int _atodbl(
   _CRT_DOUBLE * value,
   char * str
);
int _atodbl_l (
   _CRT_DOUBLE * value,
   char * str,
   locale_t locale
);
int _atoldbl(
   _LDOUBLE * value,
   char * str
);
int _atoldbl_l (
   _LDOUBLE * value,
   char * str,
   locale_t locale
);
int _atoflt(
   _CRT_FLOAT * value,
   char * str
);
int _atoflt_l(
   _CRT_FLOAT * value,
   char * str,
   locale_t locale
);

Parameters

  • value
    The double, long double, or float value produced by converting the string to a floating-point value. These values are wrapped in a structure.

  • str
    The string to be parsed to convert into a floating-point value.

  • locale
    The locale to use.

Return Value

Returns 0 if successful; possible error codes are _UNDERFLOW or _OVERFLOW, defined in the header file Math.h.

Remarks

These functions convert a string to a floating-point value. The difference between these functions and the atof family of functions is that these functions do not generate floating-point code and hence do not result in hardware exceptions. Instead, error conditions are reported as an error code.

If a string does not have a valid interpretation as a floating-point value, value is set to zero and the return value is zero.

The versions of these functions with the _l suffix are identical except that they use the locale parameter passed in instead of the current thread locale.

Requirements

Routines

Required header

_atodbl, _atoldbl, _atoflt

_atodbl_l, _atoldbl_l, _atoflt_l

<stdlib.h>

Example

// crt_atodbl.c
// Uses _atodbl to convert a string to a double precision
// floating point value.

#include <stdlib.h>
#include <stdio.h>

int main()
{
   char str1[256] = "3.141592654";
   char abc[256] = "abc";
   char oflow[256] = "1.0E+5000";
   _CRT_DOUBLE dblval;
   _CRT_FLOAT fltval;
   int retval;

   retval = _atodbl(&dblval, str1);

   printf("Double value: %lf\n", dblval.x);
   printf("Return value: %d\n\n", retval);

   retval = _atoflt(&fltval, str1);
   printf("Float value: %f\n", fltval.f);
   printf("Return value: %d\n\n", retval);

   // A non-floating point value: returns 0.
   retval = _atoflt(&fltval, abc);
   printf("Float value: %f\n", fltval.f);
   printf("Return value: %d\n\n", retval);

   // Overflow.
   retval = _atoflt(&fltval, oflow);
   printf("Float value: %f\n", fltval.f);
   printf("Return value: %d\n\n", retval);

   return 0;
}

Double value: 3.141593
Return value: 0

Float value: 3.141593
Return value: 0

Float value: 0.000000
Return value: 0

Float value: 1.#INF00
Return value: 3

See Also

Concepts

Data Conversion

Floating-Point Support

Locale

atof, _atof_l, _wtof, _wtof_l