「C言語」atof()メソッドで文字列型をfloat型に変換するサンプル

2020年11月24日

説明
atofで文字列をfloat型の数値に変換
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char str[20] = "56.7688";
float res;
res = atof(str);
printf("res=%f\n", res);
return 0;
}
#include <stdio.h> #include <stdlib.h> int main(void) { char str[20] = "56.7688"; float res; res = atof(str); printf("res=%f\n", res); return 0; }
#include <stdio.h>
#include <stdlib.h>

int main(void) {
  char str[20] = "56.7688";
  float res;

  res = atof(str);
  printf("res=%f\n", res);

  return 0;
}

実行結果
res=56.768799

C言語

Posted by arkgame