From f162c15a5aba73107bdb9a27f9d9bf2ca4c50b32 Mon Sep 17 00:00:00 2001 From: mudrd8mz Date: Tue, 8 Sep 2009 21:45:44 +0000 Subject: [PATCH] NOBUG: Added a new function handling with the grades precission We should provide a common approach to float grade values so modules will be consistent in grading algorithm. That is why I push it here. Note that basically this complements grade_floats_different(). Used in Workshop 2.0. --- lib/gradelib.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/gradelib.php b/lib/gradelib.php index 1d67131772..75a7439d6d 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -1285,7 +1285,7 @@ function grade_course_reset($courseid) { } /** - * Convert number to 5 decimalfloat, empty tring or null db compatible format + * Convert number to 5 decimalfloat, empty string or null db compatible format * (we need this to decide if db value changed) * * @param mixed $number @@ -1313,4 +1313,17 @@ function grade_floats_different($f1, $f2) { return (grade_floatval($f1) !== grade_floatval($f2)); } -?> +/** + * Compare two float numbers safely. Uses 5 decimals php precision. + * + * Do not use rounding for 10,5 at the database level as the results may be + * different from php round() function. + * + * @since 2.0 + * @param float $f1 + * @param float $f2 + * @return bool true if the values should be considered as the same grades + */ +function grade_floats_equal($f1, $f2) { + return (grade_floatval($f1) === grade_floatval($f2)); +} -- 2.39.5