Using a number_decimal, if one enters a large value, it is converted to scientific notation.

For example, in a field I enter "1000000" and submit and when I view I see I have "1e+06". This is fine. However, if I edit that page and do not change that field it will be resaved as "106".

Essentially, the module converts TO scientific notation but not FROM, which results in drastically changing values when resaving a page unless one manually reenters the value each time one makes any change at all to the page.

Comments

yched’s picture

Status: Active » Closed (duplicate)

This is a duplicate of http://drupal.org/node/115632 (but the way you present the bug makes it critical in fact)

On a related note, see http://drupal.org/node/109246 about additional numeric datatypes.

bchoc’s picture

Sorry ... I did look for duplicates before posting, but 115632 somehow didn't equate to the same thing in my mind, so I guess I overlooked it.

yched’s picture

No problem. As I wrote, your 'version' of the bug clearly showed its 'critical' level.

joshk’s picture

Adding the following to the numeric_field() function within the switch($op) block prevents the worst of this behavior:

      case 'load':
        if ($field['type'] == 'number_decimal') {
          $db_info = content_database_info($field);
          $column_names = array();
          foreach ($db_info['columns'] as $column => $attributes) {
            $column_names[] = $attributes['column'] .' AS '. $column;
          }
          if ($field['multiple']) {
            $result = db_query('SELECT '. implode(', ', $column_names) .' FROM {'. $db_info['table'] .'} WHERE vid = %d ORDER BY delta', $node->vid);
            $values = array();
            while ($value = db_fetch_array($result)) {
              foreach ($value as $key => $val) {
                $value[$key] = (float) $value;
              }
              $values[] = $value;
            }
            $additions = array($field['field_name'] => $values);
          }
          else {
            $result = db_query('SELECT '. implode(', ', $column_names) .' FROM {'. $db_info['table'] .'} WHERE vid = %d', $node->vid);
            $value = db_fetch_array($result);
            foreach ($value as $key => $val) {
              $value[$key] = (float) $val;
            }
            $additions = array($field['field_name'] => array($value));
          }
        }
        return $additions;
      break;

The real issue is that columns of type float shouldn't be used to store decimal data, as even with this code, we only get six significant digits of precision.