when using setprecision(2) when i try to display the number .90 it olny outputs .9
is there anyway to make it so that it display .90 instead of .9.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float a = 0.90;
cout << fixed;
cout << setprecision(2) << a;
}
What SoapyCro says. Using only setprecision(2) does 2 places so .9 would be correct because 0.9 is 2 digits. Including cout << fixed; like SoapyCro did forces 2 places after the decimal.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.