+ 2
How to display a 0 after a decimal
If I want to show a dollar amount like $1.50, how do I get the 0 to display?
3 Antworten
+ 1
When I use float, the 0 in the hundreths place does not display. Do I need to use double?
+ 1
Here's an example:
#include<iostream>
#include <iomanip>
using namespace std;
int main()
{
float a=111.5;
float b= 2.333333;
cout << fixed << setprecision(2);
cout << "Your a= " <<a;
cout << "Your b= " <<b;
return 0;
}
You have to include this line at the beginning of your code:
cout << fixed << setprecision(2);
And don't forget to include iomanip library! :)
0
i think u should write float instead of int