Mega Code Archive

 
Categories / C++ Tutorial / Development
 

Using showpoint to control the printing of trailing zeros anddecimal points for doubles

#include <iostream> using std::cout; using std::endl; using std::showpoint; int main() {    cout << "Before using showpoint" << endl       << "9.9900 prints as: " << 9.9900 << endl       << "9.9000 prints as: " << 9.9000 << endl       << "9.0000 prints as: " << 9.0000 << endl << endl;    cout << showpoint         << "After using showpoint" << endl       << "9.9900 prints as: " << 9.9900 << endl       << "9.9000 prints as: " << 9.9000 << endl       << "9.0000 prints as: " << 9.0000 << endl;    return 0; } Before using showpoint 9.9900 prints as: 9.99 9.9000 prints as: 9.9 9.0000 prints as: 9 After using showpoint 9.9900 prints as: 9.99000 9.9000 prints as: 9.90000 9.0000 prints as: 9.00000