I fixed up the database creation
[moodle.git] / grade / report / lib.php
CommitLineData
38b9e8a8 1<?php
2/**
3 * format grade using lang specific decimal point and thousand separator
4 * the result is suitable for printing on html page
5 * @param float $gradeval raw grade value pulled from db
6 * @return string $gradeval formatted grade value
7 */
8function get_grade_clean($gradeval) {
9 global $CFG;
10
11 if (is_null($gradeval)) {
12 $gradeval = '';
13 } else {
14 // decimal points as specified by user
15 $decimals = get_user_preferences('grade_report_decimalpoints', $CFG->grade_report_decimalpoints);
16 $gradeval = number_format($gradeval, $decimals, get_string('decpoint', 'langconfig'), get_string('thousandsep', 'langconfig'));
17 }
18
19 return $gradeval;
20
21 /*
22 // commenting this out, if this is added, we also need to find the number of decimal place preserved
23 // so it can go into number_format
24 if ($gradeval != 0) {
25 $gradeval = rtrim(trim($gradeval, "0"), ".");
26 } else {
27 $gradeval = 0;
28 }
29 */
30
31}
32
33/**
34 * Given a user input grade, format it to standard format i.e. no thousand separator, and . as decimal point
35 * @param string $gradeval grade value from user input, language specific format
36 * @return string - grade value for storage, en format
37 */
38function format_grade($gradeval) {
39
40 $decimalpt = get_string('decpoint', 'langconfig');
41 $thousandsep = get_string('thousandsep', 'langconfig');
42 // replace decimal point with '.';
43 $gradeval = str_replace($decimalpt, '.', $gradeval);
44 // thousand separator is not useful
45 $gradeval = str_replace($thousandsep, '', $gradeval);
46
47 return clean_param($gradeval, PARAM_NUMBER);
48}
49?>