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



commit 6204c3cbb1b915d788e373485a452a1e571f6a99
Author: Pedro Martinez-Julia <pedromj um es>
Date:   Mon Mar 7 23:31:40 2011 +0100

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

 src/egg-discrete.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/src/egg-discrete.c b/src/egg-discrete.c
index a051282..fe910cc 100644
--- a/src/egg-discrete.c
+++ b/src/egg-discrete.c
@@ -47,7 +47,7 @@ egg_discrete_from_percent (guint percentage, guint levels)
 		egg_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);
 }
 
 /**
@@ -69,7 +69,7 @@ egg_discrete_to_percent (guint discrete, guint levels)
 		egg_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]