Cpp - Write program to output 23.987 as a fixed point number rounded to two decimal places.

Requirements

Write program to output 23.987 as a fixed point number rounded to two decimal places.

Right-justifying the output in a field with a width of 12

Demo

#include <iostream> 
#include <iomanip>     // For setw() and setprecision() 
using namespace std; 
int main() /*from   www.  jav  a2 s .com*/
{ 
    double x2 = 23.987; 
    cout << fixed << setprecision(2) << right << setw(12) << x2 << endl; 
    return 0; 
}

Result

Related Exercise