Share via


_atodbl, _atodbl_l, _atoldbl, _atoldbl_l, _atoflt _atoflt_l

문자열을 double (_atodbl), long double (_atoldbl), 또는 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,
   const char * str
);
int _atoflt_l(
   _CRT_FLOAT * value,
   const char * str,
   locale_t locale
);

매개 변수

  • value
    문자열을 부동 소수점 값으로 변환하여 생성된 double, long double, 또는 float 값입니다. 이러한 값은 구조체에 래핑됩니다.

  • str
    부동 소수점 값으로 변환하기 위해 분석 되는 문자열입니다.

  • locale
    사용할 로캘입니다.

반환 값

성공하면 0를 반환합니다. 가능한 오류 코드는 _UNDERFLOW 또는 _OVERFLOW이며, Math.h 에 정의 되어있습니다.

설명

이러한 함수는 문자열을 부동 소수점 값으로 변환합니다. 이러한 함수와 atof 함수 패밀리의 차이점은 이러한 함수는 부동 소수점 코드를 생성하지 않으며 하드웨어 예외를 발생시키지 않는 다는 것입니다. 대신에 오류 조건은 오류 코드로 보고 됩니다.

만약 문자열이 부동 소수점 값으로서 유효한 해석을 가지지 않는다면 value 는 0으로 설정 되고 반환 값은 0이 됩니다.

현재 스레드 로캘 대신에 전달 된 로캘 매개 변수를 사용하는 경우를 제외하고는 _l 접미사가 있는 이러한 함수의 버전과 접미사가 없는 버전은 동일합니다.

요구 사항

루틴

필수 헤더

_atodbl, _atoldbl, _atoflt

_atodbl_l, _atoldbl_l, _atoflt_l

<stdlib.h>

예제

// 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;
}
  

참고 항목

참조

데이터 변환

부동 소수점 지원

로캘

atof, _atof_l, _wtof, _wtof_l