diff --git a/lib/misc.vala b/lib/misc.vala index 98c9dda..d1f136b 100644 --- a/lib/misc.vala +++ b/lib/misc.vala @@ -55,7 +55,8 @@ namespace LibSernatur { * @return Returns a string of the percentage */ public static string format_double (double value) { - return (value * 100).to_string () + "%"; + // Remove the double precision by converting to float + return ((float) (value * (double) 100)).to_string () + "%"; } } diff --git a/test/percentage.vala b/test/percentage.vala index 4f917fa..acc295a 100644 --- a/test/percentage.vala +++ b/test/percentage.vala @@ -2,8 +2,10 @@ using LibSernatur.Misc; void add_percentage_tests () { Test.add_func ("/sernatur/test/percentage", () => { + assert (Percentage.format_float ((float) 0.07) == "7%"); assert (Percentage.format_float ((float) 0.43) == "43%"); assert (Percentage.format_float ((float) 1) == "100%"); + assert (Percentage.format_double (0.07) == "7%"); assert (Percentage.format_double (0.43) == "43%"); assert (Percentage.format_double (1) == "100%"); });