]> git.mjollnir.org Git - moodle.git/commitdiff
[MDL-14788] Don't store empty number fields as 0
authorrobertall <robertall>
Tue, 27 May 2008 07:43:14 +0000 (07:43 +0000)
committerrobertall <robertall>
Tue, 27 May 2008 07:43:14 +0000 (07:43 +0000)
mod/data/field/number/field.class.php

index 073a091ad6b68579af3e487d8d69da941eb4b493..fa3bc07a9a42a25ffd1b67a2d89a505e4e524f52 100755 (executable)
@@ -34,7 +34,12 @@ class data_field_number extends data_field_base {
         $content = new object;
         $content->fieldid = $this->field->id;
         $content->recordid = $recordid;
-        $content->content = (float)$value;
+        $value = trim($value);
+        if (strlen($value) > 0) {
+            $content->content = floatval($value);
+        } else {
+            $content->content = null;
+        }
 
         if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
             $content->id = $oldcontent->id;