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.

Recommended Answers

All 2 Replies

#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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.