字符串在科学记数法C ++到双重转换 [英] String in scientific notation C++ to double conversion
本文介绍了字符串在科学记数法C ++到双重转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据库填充了两个如下所示:
I've got a database filled up with doubles like the following one:
1.60000000000000000000000000000000000e+01
有人知道如何将这样的数字转换为C ++中的双数吗?
Does anybody know how to convert a number like that to a double in C++?
有没有标准的方式来做这种类型的事情?
Is there a "standard" way to do this type of things? Or do I have to roll my own function?
现在我正在这样做:
#include <string>
#include <sstream>
int main() {
std::string s("1.60000000000000000000000000000000000e+01");
std::istringstream iss(s);
double d;
iss >> d;
d += 10.303030;
std::cout << d << std::endl;
}
谢谢!
推荐答案
这样的东西?这将是C ++的做法...
Something like this? This would be the "C++" way of doing it...
#include <sstream>
using namespace std;
// ...
string s = "1.60000000000000000000000000000000000e+01";
istringstream os(s);
double d;
os >> d;
cout << d << endl;
打印16。
这篇关于字符串在科学记数法C ++到双重转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文