diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index a03f491..7c6efb9 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -277,37 +277,21 @@ void HiScoreTable::updateFade() std::string HiScoreTable::format(int number) { const std::string separator = "."; - - if (number < 1000) - { - return std::to_string(number); - } + const std::string score = std::to_string(number); - else if (number >= 1000 && number < 1000000) + int index = (int)score.size() - 1; + std::string result = ""; + int i = 0; + while (index >= 0) { - const std::string num1 = std::to_string(number / 1000); - const std::string num2 = std::to_string(number % 1000); - return num1 + separator + fillZeros(num2); - } - - else if (number >= 1000000) - { - const std::string num1 = std::to_string(number / 1000000); - const std::string num2 = std::to_string(number % 1000000 / 1000); - const std::string num3 = std::to_string(number % 1000000 % 1000); - return num1 + separator + fillZeros(num2) + separator + fillZeros(num3); - } - - return std::to_string(number); -} - -// Añade ceros a una cadena -std::string HiScoreTable::fillZeros(std::string text, int size) -{ - std::string result = text; - for (int i=(int)text.size(); i < size; ++i) - { - result = '0' + result; + result = score.at(index) + result; + index--; + i++; + if (i == 3) + { + i = 0; + result = separator + result; + } } return result; diff --git a/source/hiscore_table.h b/source/hiscore_table.h index 9c710e9..8b90454 100644 --- a/source/hiscore_table.h +++ b/source/hiscore_table.h @@ -58,9 +58,6 @@ private: // Convierte un entero a un string con separadores de miles std::string format(int number); - // Añade ceros a una cadena - std::string fillZeros(std::string text, int size = 3); - // Transforma un valor numérico en una cadena de 6 cifras std::string scoreToString(int num);