将精度double转换为字符串 [英] Converting a precision double to a string
本文介绍了将精度double转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法将它转换成每个个人数字的字符串或数组?
这是我的代码到目前为止,虽然这与问题不完全相关:
int main(){
double n = 0;
cout<<< Giz一个数字:;
cin>> N;
double val = 1;
for(double i = 1; i< = n; i ++){
val = val * i;
}
//将val转换为字符串/数组?
}
解决方案
std :: stringstream str;
str<<<固定的< setprecision(15)<<你的号码;
您可能还对科学
感兴趣格式标志。
C ++ 11还有一些有趣的功能 std :: to_string
,您可能需要检查!
I have a large number in c++ stored as a precise double value (assuming the input 'n' is 75): 2.4891e+109
Is there any way to convert this to a string or an array of each individual digit?
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;
You may also be interested in the scientific
format flag.
C++11 also has a few interesting functions std::to_string
which you may want to check out!
这篇关于将精度double转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文