Теперь я придумал, как использовать две функции: (первая — это фактическая функция, которую я использую)
Код: Выделить всё
string doubleToString(double value)
{
string output = to_string(value);
int index = findStrAfterStr(output, ".", "0");
if (index > 0)
{
output.erase(index);
}
if (output[output.length() - 1] == '.')
{
output.erase(output.length() - 1);
}
return output;
}
Код: Выделить всё
int findStrAfterStr(string sourceStr, string firstStr, string wantedStr)
{
bool firstStrFound = false;
for (int i = 0; i < sourceStr.length(); ++i)
{
if (!firstStrFound)
{
firstStrFound = sourceStr.substr(i, firstStr.length()) == firstStr;
}
else if (sourceStr.substr(i, wantedStr.length()) == wantedStr)
{
return i;
}
}
return 0;
}
Подробнее здесь: https://stackoverflow.com/questions/785 ... -data-type
Мобильная версия