😸
[C] strtod 関数
機能
文字列を倍精度浮動小数点数(double型)に変換する関数[1]
使用例
123.456
と表示する
\n
は改行を表す エスケープシーケンス[2]
コード
printf("%f\n", strtod("123.456", NULL));
全文
#include <stdio.h>
#include <stdlib.h>
void main() {
printf("%f\n", strtod("123.456", NULL));
}
実行結果
123.456000
0.789
を変数から表示する
コード
const char *numstr = "0.789";
double num = strtod(numstr, NULL);
printf("%f\n", num);
全文
#include <stdio.h>
#include <stdlib.h>
void main() {
const char *numstr = "0.789";
double num = strtod(numstr, NULL);
printf("%f\n", num);
}
実行結果
0.789000
Discussion