C Func atof - sonkoni/Koni-Wiki GitHub Wiki

stdlib.h

atof

문자λ₯Ό μ‹€μˆ˜λ‘œ λ³€ν™˜. (Ascii TO Float)

double atof(const char *str);
// str: μ‹€μˆ˜ν¬λ©§ λ¬Έμžμ—΄
// μ‹€μˆ˜ν¬λ©§μ˜ λ¬Έμžμ—΄μ„ μ‹€μˆ˜λ‘œ λ³€ν™˜ν•˜μ—¬ λ°˜ν™˜. μ‹€νŒ¨ν•˜λ©΄ 0 λ°˜ν™˜.
// - 숫자λ₯Ό λ³€ν™˜ν•˜λ‹€κ°€ μ•ŒνŒŒλ²³, 영문자, 특수문자 λ“± 문자 λ§Œλ‚˜λŠ” μ§€μ μ—μ„œ μ€‘λ‹¨ν•œλ‹€.
// - μ²˜μŒλΆ€ν„° μˆ«μžκ°€ μ•„λ‹ˆλ©΄ μ€‘λ‹¨ν•˜κ³  0 λ°˜ν™˜ν•œλ‹€.
// - 쀑간에 곡백을 λ§Œλ‚˜λ„ μ’…λ£Œλœλ‹€.
// - μ²˜μŒλΆ€ν„° 곡백이면 κ·Έ 곡백은 κ±΄λ„ˆλ›΄λ‹€.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
    char *str = "25.32912849";    // μ‹€μˆ˜ν¬λ©§ λ¬Έμžμ—΄
    double num = atof(str);       // μ‹€μˆ˜λ‘œ λŒ€μΉ˜
    printf("%s : %.10f", str, num);
    return 0;
}
// 25.32912849 : 25.3291284900
⚠️ **GitHub.com Fallback** ⚠️