number_field_widget_validate() currently does:

    // Let PHP round the value to ensure consistent behavior across storage
    // backends.
    if ($type == 'decimal') {
      $value = round($value, $field['settings']['scale']);
    }

This has to be done at field level, in hook_field_presave(), so that this applies to programmatic saves as well.

CommentFileSizeAuthor
field_number_round.patch2.46 KByched
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Status: Needs review » Reviewed & tested by the community
+++ modules/field/modules/number/number.module	12 Nov 2009 16:52:05 -0000
@@ -192,6 +192,21 @@ function number_field_validate($obj_type
 /**
+ * Implement hook_field_presave().
+ */

Please note that all new code should use Implements. But since we have to run a global s/Implement/Implements/ anyway, no reason to hold off this patch.

This review is powered by Dreditor.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

I fixed the implements and committed this patch to CVS HEAD. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.