banshee r3568 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Sources



Author: gburt
Date: Thu Mar 27 20:25:05 2008
New Revision: 3568
URL: http://svn.gnome.org/viewvc/banshee?rev=3568&view=rev

Log:
2008-03-27  Gabriel Burt  <gabriel burt gmail com>

	* src/Core/Banshee.Services/Banshee.Sources/Source.cs: Fix formatting
	issue with showing full precision in certain cases when the value was < 2.


Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/Source.cs

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/Source.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/Source.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/Source.cs	Thu Mar 27 20:25:05 2008
@@ -441,16 +441,13 @@
                 TimeSpan span = (this as IDurationAggregator).Duration; 
                 if (span.Days > 0) {
                     double days = span.Days + (span.Hours / 24.0);
-                    builder.AppendFormat (Catalog.GetPluralString ("{0} day", "{0:0.0} days", 
-                        (int)Math.Ceiling (days)), days);
+                    builder.AppendFormat (Catalog.GetPluralString ("{0} day", "{0} days", DoubleToPluralInt (days)), FormatDouble (days));
                 } else if (span.Hours > 0) {
                     double hours = span.Hours + (span.Minutes / 60.0);
-                    builder.AppendFormat (Catalog.GetPluralString ("{0} hour", "{0:0.0} hours", 
-                        (int)Math.Ceiling (hours)), hours);
+                    builder.AppendFormat (Catalog.GetPluralString ("{0} hour", "{0} hours", DoubleToPluralInt (hours)), FormatDouble (hours));
                 } else {
                     double minutes = span.Minutes + (span.Seconds / 60.0);
-                    builder.AppendFormat (Catalog.GetPluralString ("{0} minute", "{0:0.0} minutes", 
-                        (int)Math.Ceiling (minutes)), minutes);
+                    builder.AppendFormat (Catalog.GetPluralString ("{0} minute", "{0} minutes", DoubleToPluralInt (minutes)), FormatDouble (minutes));
                 }
             }
 
@@ -464,6 +461,22 @@
             
             return builder.ToString ();
         }
+
+        private static string FormatDouble (double num)
+        {
+            if (num == (int)num)
+                return Convert.ToString ((int)num);
+            else
+                return String.Format ("{0:0.0}", num);
+        }
+        
+        private static int DoubleToPluralInt (double num)
+        {
+            if (num == (int)num)
+                return (int)num;
+            else
+                return (int)num + 1;
+        }
         
         string IService.ServiceName {
             get { return DBusServiceManager.MakeDBusSafeString (Name) + "Source"; }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]