I know we can use setprecision
to prevent a number to be rounded but what if I don't want to round all of my numbers in the list with the same decimal places? In other words, I want to keep my numbers the same as calculated and each number has its own decimal places.
For example: if we use setprecision(7)
then it will give the output up to 7 decimal places for all numbers in my list. What if I have a list of different numbers with different decimal places such as 8 or 10 decimal places? Do I need to do setprecision
for each of them? Is there any way to keep my numbers the same as the output after calculated? Ex:0.1234567, 0.123456789, 0.12345678910
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<double> myVec{0.1234567, 0.123456789, 0.12345678, 0.12345678910};
for(int i = 0; i < myVec.size(); i++)
{
cout << myVec[i] << " ";
}
return 0;
}