Write a program that prints the value of 120.456789 rounded to the nearest digit, tenth, hundredth, thousandth, and ten-thousandth. [Hint: This should make use of formatted output.]
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double x = 120.456789;
cout << fixed;
for (int i=0; i<=4; i++) {
cout << setprecision(i) << x << endl;
}
return 0;
}
Comments
Leave a comment