😸
[C] strtof 関数
機能
文字列をfloat型の値に変換する[1]
使用例
123.45 と表示する
\n は改行を表す エスケープシーケンス[2]
コード
printf("%f\n", strtof("123.45", NULL));
全文
#include <stdio.h>
#include <stdlib.h>
void main() {
printf("%f\n", strtof("123.45", NULL));
}
実行結果
123.450000
456.78 を変数から表示する
コード
char s[] = "456.78";
printf("%f\n", strtof(s, NULL));
全文
#include <stdio.h>
#include <stdlib.h>
void main() {
char s[] = "456.78";
printf("%f\n", strtof(s, NULL));
}
実行結果
456.780000
Discussion