computer_science:programming:cpp
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
computer_science:programming:cpp [2021/10/02 04:54] – mana | computer_science:programming:cpp [2021/10/02 04:59] (current) – mana | ||
---|---|---|---|
Line 13: | Line 13: | ||
Then get access to these: | Then get access to these: | ||
<code cpp> | <code cpp> | ||
- | cout << fixed << result << endl; // | + | cout << fixed << result << endl; // This will set the display to use fixed representation (default of 6 digits?) |
cout << fixed << setprecision(2) << result; // This will force cout to isplay only 2 decimals and will round to reach this result | cout << fixed << setprecision(2) << result; // This will force cout to isplay only 2 decimals and will round to reach this result | ||
+ | </ | ||
+ | <code cpp> | ||
cout << result << endl; // this would still show with the previous setprecision setting. | cout << result << endl; // this would still show with the previous setprecision setting. | ||
cout << setprecision(3) << result2; // the variable is not affect by set precision, so it would now show 3 decimals | cout << setprecision(3) << result2; // the variable is not affect by set precision, so it would now show 3 decimals | ||
- | cout << fixed << setprecision(2) << setw(15) << left << result << "End of line" << | + | cout << fixed << setprecision(2) << setw(15) << left << result << "End of line" << |
- | </ | + | Using setw we can force the display of a certain number of characters. In this case, if the variable is more than 15 characters, it will be truncated, if not then white spaces will be added. The next (optional) setting (in this case " |
computer_science/programming/cpp.1633118082.txt.gz · Last modified: 2021/10/02 04:54 by mana