【C++】atof

C 标准库 - <stdlib.h>

描述

C 库函数 double atof(const char *str) 把参数 str 所指向的字符串转换为一个浮点数(类型为 double 型)。

声明

下面是 atof() 函数的声明。

double atof(const char *str)

参数

  • str -- 要转换为浮点数的字符串。

返回值

函数返回转换后的双精度浮点数,如果没有执行有效的转换,则返回零(0.0)。

/* atof example: sine calculator */
#include <stdio.h>      /* printf, fgets */
#include <stdlib.h>     /* atof */
#include <math.h>       /* sin */

int main()
{
	double n, m;
	double pi = 3.1415926535;
	char buffer[256];
	printf("Enter degrees: ");
	fgets(buffer, 256, stdin);
	n = atof(buffer);
	m = sin(n*pi / 180);
	printf("The sine of %f degrees is %f\n", n, m);
	return 0;
}

参考

http://www.cplusplus.com/reference/cstdlib/atof/

http://www.runoob.com/cprogramming/c-function-atof.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值