首页 > 编程知识 正文

c语言atof函数atof函数与C 中的示例,c语语言转换函数

时间:2023-05-06 01:21:16 阅读:239781 作者:461

c语言atof函数

C ++ atof()函数 (C++ atof() function)

atof() function is a library function of cstdlib header. It is used to convert the given string value to the double value. It accepts a string containing a floating-point number and returns its double value.

atof()函数是cstdlib标头的库函数。 它用于将给定的字符串值转换为双精度值。 它接受包含浮点数的字符串,并返回其双精度值。

Syntax of atof() function:

atof()函数的语法:

C++11:

C ++ 11:

double atof (const char* str);

Parameter(s):

参数:

str – represents a string containing a floating-point number.

str –表示包含浮点数的字符串。

Return value:

返回值:

The return type of this function is double, it returns the double converted value.

该函数的返回类型为double ,它返回double转换后的值。

Example:

例:

Input: str = "123.456"; Function call: atof(str); Output: 123.456 C ++代码演示atof()函数的示例 (C++ code to demonstrate the example of atof() function) // C++ code to demonstrate the example of// atof() function#include <iostream>#include <cstdlib>#include <string.h>using namespace std;// main() sectionint main(){ char str[50]; strcpy(str, "123.456"); cout << "atof("" << str << ""): " << atof(str) << endl; strcpy(str, "-123.456"); cout << "atof("" << str << ""): " << atof(str) << endl; strcpy(str, "0.123456"); cout << "atof("" << str << ""): " << atof(str) << endl; strcpy(str, "-0.123456"); cout << "atof("" << str << ""): " << atof(str) << endl; strcpy(str, "12345678.123456"); cout << "atof("" << str << ""): " << atof(str) << endl; strcpy(str, "-12345678.123456"); cout << "atof("" << str << ""): " << atof(str) << endl; return 0;}

Output

输出量

atof("123.456"): 123.456atof("-123.456"): -123.456atof("0.123456"): 0.123456atof("-0.123456"): -0.123456atof("12345678.123456"): 1.23457e+07atof("-12345678.123456"): -1.23457e+07

Reference: C++ atof() function

参考: C ++ atof()函数

翻译自: https://www.includehelp.com/cpp-tutorial/atof-function-with-example.aspx

c语言atof函数

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。