😸
[C] atof 関数
機能
文字列を浮動小数点数(double型)に変換する関数[1]
使用例
123.45 と表示する
\n は改行を表す エスケープシーケンス[2]
コード
printf("%f\n", atof("123.45"));
全文
#include <stdio.h>
#include <stdlib.h>
void main() {
printf("%f\n", atof("123.45"));
}
実行結果
123.450000
文字列変数 "0.789" を変換して表示する
コード
char str[] = "0.789";
printf("%f\n", atof(str));
全文
#include <stdio.h>
#include <stdlib.h>
void main() {
char str[] = "0.789";
printf("%f\n", atof(str));
}
実行結果
0.789000
Discussion