Hi
I am fairly new to programming. Can anyone help me in getting it to display zeros to the left of a decimal point? For example, instead of displaying 5 show as 005?
Printable View
Hi
I am fairly new to programming. Can anyone help me in getting it to display zeros to the left of a decimal point? For example, instead of displaying 5 show as 005?
Set the fill for cout to be whatever character you want. Then when you have a width longer than the length of the value, empty space will be repaced with that character.
Code:#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
double a = 5.0;
int b = 5;
cout.fill('0');
cout << setw(3) << a << endl;
cout << setw(3) << b << endl;
return 0;
}