Dotcpp  >  编程教程  >  stdlib.h头文件  >  C语言atof()函数:将字符串转换为浮点值

C语言atof()函数:将字符串转换为浮点值

点击打开在线编译器,边学边练

函数名:atof

头文件:<stdlib.h>

函数原型: double atof(const char *s);

功能: 将字符串转换为浮点值

参数:const char *s  为要转换的字符串 

返回值:返回转换后的浮点值


程序例:将字符串"5257.1314"转换成浮点值,并输出字符串和转换的浮点值

#include<stdio.h>

#include<stdlib.h>

int main(void){

   float r;

   char *s="5257.1314";

   r=atof(s);

   printf("string = %s\nfloat= %f\n",s,r);  

   return 0;

}

 

运行结果

string = 5257.1314
float= 5257.131348



本文固定URL:https://www.dotcpp.com/course/543

C语言函数库
assert.h头文件
ctype.h头文件
float.h头文件
io.h头文件
math.h头文件
mem.h头文件
setjmp.h头文件
stdio.h头文件
stdlib.h头文件
sigal.h头文件
string.h头文件
time.h头文件
Dotcpp在线编译      (登录可减少运行等待时间)