[gnome-power-manager] Fixed #644143, how to convert from percentage to discrete and vice-versa.



commit 38c3d6efd7b429810034be04f9be33dcf51a2ee2
Author: Pedro Martinez-Julia <pedromj um es>
Date:   Mon Mar 7 23:18:55 2011 +0100

    Fixed #644143, how to convert from percentage to discrete and vice-versa.
    
    Signed-off-by: Richard Hughes <richard hughsie com>

 src/gpm-common.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/src/gpm-common.c b/src/gpm-common.c
index dc05944..31f2d9c 100644
--- a/src/gpm-common.c
+++ b/src/gpm-common.c
@@ -182,7 +182,7 @@ gpm_discrete_from_percent (guint percentage, guint levels)
 		g_warning ("levels is 0!");
 		return 0;
 	}
-	return ((gfloat) percentage * (gfloat) (levels - 1)) / 100.0f;
+	return (guint) ((((gfloat) percentage * (gfloat) (levels - 1)) / 100.0f) + 0.5f);
 }
 
 /**
@@ -204,7 +204,7 @@ gpm_discrete_to_percent (guint discrete, guint levels)
 		g_warning ("levels is 0!");
 		return 0;
 	}
-	return (guint) ((gfloat) discrete * (100.0f / (gfloat) (levels - 1)));
+	return (guint) (((gfloat) discrete * (100.0f / (gfloat) (levels - 1))) + 0.5f);
 }
 
 /**



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