设置cout的输出精度

I read the data from the file, the data is like:

6336253000000,0,2.89729972727,0.499999869261,0.499999952934,-1.07080008367,0.499999869261,2.36749995293,0.499999916327,0,0.000789873880191,0.000378644598289,0.000136312062988,0.000242332550508,0.000378644598289,0.000136312062988,0.000242332550508,0,-1.14380808558,-0.548311212244,-0.197392069441,-0.350919208869,-0.548311212244,-0.197392069441,-0.350919208869,0,-6.13606402873,-14.2367822588,-11.0049472307,8.71407191407,1.00874062366,0.391059638015,-0.0348915901406,29.999309435

But when I use cout to output, they are like:

time:29.9993
--q_data---
2.8973 0.5 0.5 -1.0708 0.5 2.3675 0.5 
--vel_data---
0.000789874 0.000378645 0.000136312 0.000242333 0.000378645 0.000136312 0.000242333 
--acc_data---
-1.14381 -0.548311 -0.197392 -0.350919 -0.548311 -0.197392 -0.350919 
--tau_data---
-6.13606 -14.2368 -11.0049 8.71407 1.00874 0.39106 -0.0348916 

The percision is just 5 bit.

The way to set the percision

1. the percision after decimal point “.”

fixed: the percision after decimal point “.”
setprecision(n): how many bit of percision

cout<<fixed<<setprecision(10)<<q_data[i]<<" ";

show that:

time:30.0092674660
--q_data---
2.8972508816 0.4999764541 0.4999915234 -1.0708150694 0.4999764541 2.3674915234 0.4999849306 
--vel_data---
-0.0106001436 -0.0050813771 -0.0018293141 -0.0032520997 -0.0050813771 -0.0018293141 -0.0032520997 
--acc_data---
-1.1437888021 -0.5482855346 -0.1973887416 -0.3509086913 -0.5482855346 -0.1973887416 -0.3509086913 
--tau_data---
-6.1370589838 -14.2374616395 -11.0060768862 8.7133454371 1.0087414475 0.3910277370 -0.0348874264
2. whole percision, including “.”

without fixed

cout<<setprecision(10)<<q_data[i]<<" ";
发布了16 篇原创文章 · 获赞 1 · 访问量 260

猜你喜欢

转载自blog.csdn.net/weixin_45366564/article/details/103775546