Index: theme.inc =================================================================== --- theme.inc +++ theme.inc @@ -33,7 +33,7 @@ $row = array(); $row[] = drupal_render($form['info'][$id]['name']); $row[] = drupal_render($form['info'][$id]['justification']); - $row[] = drupal_render($form['info'][$id]['has_calc']) . drupal_render($form['info'][$id]['calc']); + $row[] = drupal_render($form['info'][$id]['has_calc']) . drupal_render($form['info'][$id]['calc']) . drupal_render($form['info'][$id]['precision']); $row[] = drupal_render($form['columns'][$id]); $row[] = drupal_render($form['info'][$id]['separator']); if (!empty($form['info'][$id]['sortable'])) { @@ -225,5 +225,5 @@ } return; - -} \ No newline at end of file + +} Index: views_calc_table.inc =================================================================== --- views_calc_table.inc +++ views_calc_table.inc @@ -68,7 +68,28 @@ '#process' => array('views_process_dependency'), '#dependency' => array('edit-style-options-info-'. $safe .'-has-calc' => array(TRUE)), '#multiple' => TRUE, + '#prefix' => '', ); + $form['info'][$field]['precision'] = array( + '#type' => 'fieldset', + '#title' => t('Round result'), + '#description' => t('Number of decimals to display.
Leave blank to get full display.'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + foreach ($options as $funct => $name) { + if ($funct != 'COUNT') { // COUNT is always an integer, there's no use in rounding it. + $form['info'][$field]['precision'][$funct] = array( + '#type' => 'textfield', + '#description' => $name, + '#default_value' => isset($this->options['info'][$field]['precision'][$funct]) ? $this->options['info'][$field]['precision'][$funct] : '', + '#size' => 2, + '#maxlength' => 2, + '#element_validate' => array('_views_calc_digit_validate'), + ); + } + } } } @@ -167,9 +188,15 @@ foreach ($this->view->field as $field) { $query_field = substr($field->field, 0, 3) == 'cid' ? $field->definition['calc'] : $field->table .'.'. $field->field; $query_alias = $field->field_alias; + $precision = $this->view->style_plugin->options['info'][$field->field]['precision'][$calc]; if (in_array($field->field, $fields)) { // Calculated fields. - $this->view->query->add_field(NULL, "$calc($query_field)", $query_alias); + if ((isset($precision)) && (ctype_digit($precision))) { + $this->view->query->add_field(NULL, "ROUND($calc($query_field), $precision)", $query_alias); + } + else { + $this->view->query->add_field(NULL, "$calc($query_field)", $query_alias); + } $this->view->query->add_table($field->table, NULL, NULL, $field->table); } else { @@ -206,10 +233,16 @@ foreach ($this->view->field as $field) { $query_field = substr($field->field, 0, 3) == 'cid' ? $field->definition['calc'] : $field->table .'.'. $field->field; $query_alias = $field->field_alias; + $precision = $this->view->style_plugin->options['info'][$field->field]['precision'][$calc]; $this->view->query->add_table($field->table, NULL, NULL, $field->table); if (!empty($fields) && in_array($field->field, $fields)) { // Calculated fields. - $this->view->query->add_field(NULL, "$calc($query_field)", $query_alias); + if ((isset($precision)) && (ctype_digit($precision))) { + $this->view->query->add_field(NULL, "ROUND($calc($query_field), $precision)", $query_alias); + } + else { + $this->view->query->add_field(NULL, "$calc($query_field)", $query_alias); + } } else { // Empty fields that have no calculations. @@ -241,4 +274,4 @@ } return $calc_fields; } -} \ No newline at end of file +}