common.cpp 526 B

12345678910111213141516171819202122232425
  1. #include "common.h"
  2. int nbDigitsFromNbLines(size_t nbLines)
  3. {
  4. int nbDigits = 0; // minimum number of digit should be 4
  5. if (nbLines < 10) nbDigits = 1;
  6. else if (nbLines < 100) nbDigits = 2;
  7. else if (nbLines < 1000) nbDigits = 3;
  8. else if (nbLines < 10000) nbDigits = 4;
  9. else if (nbLines < 100000) nbDigits = 5;
  10. else if (nbLines < 1000000) nbDigits = 6;
  11. else // rare case
  12. {
  13. nbDigits = 7;
  14. nbLines /= 1000000;
  15. while (nbLines)
  16. {
  17. nbLines /= 10;
  18. ++nbDigits;
  19. }
  20. }
  21. return nbDigits;
  22. }