fix double precision problem
This commit is contained in:
parent
346be0e9ac
commit
a0d1af51c4
@ -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 () + "%";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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%");
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user