fork(6) download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. void printFloat(float number) {
  7. cout << ((number <= -.05) ? "-" : "") << abs(number);
  8. }
  9.  
  10. int main() {
  11. cout.setf(ios::fixed,ios::floatfield);
  12. cout.precision(1);
  13.  
  14. printFloat(.049); cout << endl;
  15. printFloat(.05); cout << endl;
  16. printFloat(.051); cout << endl;
  17.  
  18. printFloat(-.049); cout << endl;
  19. printFloat(-.05); cout << endl;
  20. printFloat(-.051); cout << endl;
  21. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
0.0
0.1
0.1
0.0
-0.1
-0.1