将精度double转换为字符串 [英] Converting a precision double to a string
本文介绍了将精度double转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个大数字在c ++存储为一个精确的double值(假设输入'n'是75):2.4891e + 109
I have a large number in c++ stored as a precise double value (assuming the input 'n' is 75): 2.4891e+109
这里是我的代码到目前为止,虽然它不完全相关的问题:
Here's my code so far, although it's not entirely relevant to the question:
int main(){
double n = 0;
cout << "Giz a number: ";
cin >> n;
double val = 1;
for(double i = 1; i <= n; i++){
val = val * i;
}
//Convert val to string/array here?
}
推荐答案
std::stringstream str;
str << fixed << setprecision( 15 ) << yournumber;
您也可能对科学
格式标志。
C ++ 11也有一些有趣的函数 std :: to_string
,您可以查看!
C++11 also has a few interesting functions std::to_string
which you may want to check out!
这篇关于将精度double转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文