Remove trailing zeros from the output of Time::get_string().
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Tue, 23 Oct 2007 19:57:13 +0000 (19:57 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Tue, 23 Oct 2007 19:57:13 +0000 (19:57 +0000)
git-svn-id: http://svn.voria.com/code@952 1f10aa63-cdf2-0310-b900-c93c546f37ac

synfig-core/trunk/src/synfig/time.cpp

index 4edc8af..255359b 100644 (file)
@@ -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);
                }