字符串浮充转换? [英] string to float conversion?
本文介绍了字符串浮充转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道可以用什么样的算法,采取类似4.72变成了浮点数据类型,等于
浮动X = 4.72;
解决方案
scanf函数
,运营商的GT;>
的istreams和 strtof
将是显而易见的选择。
有是的还有 ATOF
,但是,像的atoi
,它缺乏一种方式告诉你有输入错误,所以一般最好是避免两者。
I'm wondering what sort of algorithm could be used to take something like "4.72" into a float data type, equal to
float x = 4.72;
解决方案
scanf
, operator>>
for istreams, and strtof
would be the obvious choices.
There is also atof
, but, like atoi
, it lacks a way to tell you there was an error in the input, so it's generally best to avoid both.
这篇关于字符串浮充转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文