fork download
  1. #include <iostream>
  2.  
  3. int func(double value) {
  4. std::string text = std::to_string(value);
  5. int counter = 0;
  6. bool flag = false;
  7.  
  8. for ( int i = text.size()-1; i >= 0; i-- ) {
  9. if ( text[i] != '0' ) {
  10. flag = true;
  11. }
  12. if ( flag == true && text[i] != '.' ) {
  13. counter += 1;
  14. }
  15. }
  16.  
  17. return counter;
  18. }
  19.  
  20. int main() {
  21. double number = 42.334501;
  22. double number2 = 42334501.0000;
  23.  
  24. std::cout << func(number) << "\n" << func(number2);
  25.  
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
8
8