🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

rounding vector

Started by
3 comments, last by pbivens67 3 years, 2 months ago

I am trying to round a double vector to 2 decimal places, but it prints out the number to 6 decimal places.

		for (int i = 0; i < count; i++)
		{
			cout << fixed << setw(4) << round(v_monthly_investment[i]) * 100 / 100 << " ";
			cout << fixed << setw(4) << round(v_yearly_rate[i]) * 100 / 100 << " ";
			cout << fixed << setw(4) << round(v_years[i]) * 100 / 100 << " ";
			cout << setw(2) << round(v_future_value[i]*100.0)/100.0 << endl;
		}
Advertisement

I used setprecision(2) and it worked thanks

Only the output is rounded, not the vector itself. A double has 15 significant digits always, you can only reduce the number of digits printed.

thanks I solved my problem

This topic is closed to new replies.

Advertisement