fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. float num = 3.14159;
  6. cout << fixed;
  7. cout.precision(2);
  8. cout << num << endl;
  9. printf("%.2f", num); //apenas se for usar em C puro, não use em C++
  10. }
  11.  
  12. //https://pt.stackoverflow.com/q/94564/101
Success #stdin #stdout 0s 4372KB
stdin
Standard input is empty
stdout
3.14
3.14