私は負数である可能性がある秒数を含む倍精度を持っています.H:mm:ss.hhhの形式の文字列が必要ですまたは-H:mm:ss.hhh秒を時、分、秒に変換します。秒の秒数を返します。
std::string getFormattedTime(double seconds)
{
// magic voodoo
}
時間がゼロの場合は省略する必要があります。私は、さまざまな丸めと精度の問題で二回それをbuggeredアップしましたので、私は助けを求めるための時間だった考え出し:)
std::string getLabelForPosition(double seconds)
{
bool negative = seconds < 0.0;
if (negative)
seconds *= -1.0;
double mins = std::floor(std::round(seconds)/60.0);
double secs = seconds - mins * 60.0;
std::stringstream s;
if (negative)
s << "-";
s << mins << ":" << std::fixed << std::setprecision(decimalPlaces) << secs;
return s.str();
}
まず、関数内に空白文字列を作成したいとします。次に、このページを参照してintに文字列を追加します。 https://stackoverflow.com/questions/45505477/append-int-to-stdstringそれを読んだら、単なるすべての単位変換を行い、適切な句読点と一緒にそれらを追加するだけです。 –