From: dooglus Date: Tue, 23 Oct 2007 19:57:13 +0000 (+0000) Subject: Remove trailing zeros from the output of Time::get_string(). X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=a4f8d89f6d124bfa872551bf5ef8d2d3f6e37da3;p=synfig.git Remove trailing zeros from the output of Time::get_string(). git-svn-id: http://svn.voria.com/code@952 1f10aa63-cdf2-0310-b900-c93c546f37ac --- diff --git a/synfig-core/trunk/src/synfig/time.cpp b/synfig-core/trunk/src/synfig/time.cpp index 4edc8af..255359b 100644 --- a/synfig-core/trunk/src/synfig/time.cpp +++ b/synfig-core/trunk/src/synfig/time.cpp @@ -246,7 +246,19 @@ Time::get_string(float fps, Time::Format format)const if(format<=FORMAT_FULL || second || !started) { if(abs(second-floor(second))>=epsilon_()) - ret+=strprintf("%0.8fs",second); + { + String seconds(strprintf("%0.8f",second)); + + // skip trailing zeros + int count = 0; + for (String::reverse_iterator i = seconds.rbegin(); (*i) == '0'; i++) + count++; + + // if we removed too many, go back one place, leaving one zero + if (*i < '0' || *i > '9') count--; + + ret += seconds.substr(0, seconds.size()-count) + "s"; + } else ret+=strprintf("%0.0fs",second); }