Created
August 24, 2012 16:35
-
-
Save rocarvaj/3452633 to your computer and use it in GitHub Desktop.
Printing tips C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::cout << std::setw(2) << setfill('0') << myNumber; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
#include <sstream> | |
double myNumber1 = 234234152.0055345; | |
double myNumber2 = 222121252.0055345; | |
stringstream ss; | |
ss.setf(ios::fixed); | |
ss.precision(2); | |
ss << setw(12) << right << "myNumber1" << "\t" << "myNumber2" << endl; | |
ss << setw(12) << right << myNumber1 << "\t" << myNumber2 << endl; | |
cout << ss.str(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int main() | |
{ | |
double d = 1.23; | |
std::cout.setf(std::ios::fixed); | |
std::cout.precision(2); | |
std::cout << d; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment