Decimal (Numeric)

Last updated on
11 February 2018

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

The numeric data type is actually MySQL's Decimal. It allows you to specify the precision and scale of a number. Precision is the total number of significant digits in the number and scale is the total number of digits to the right of the decimal point. For example, 123.4567 has a precision of 7 and a scale of 4.

Sample Code:
$field['fieldname'] = array(
  'type' => 'numeric', 
  'unsigned' => TRUE, 
  'precision' => 5, 
  'scale' => 2, 
  'not null' => FALSE, 
  'description' => t('Field fieldname for table tablename.'),
);
MySQL mappings in the schema.inc file:
      'numeric:normal'  => 'DECIMAL',

We use DECIMAL data type to store exact numeric values, where we do not want any rounding off,  but exact and accurate values. A Decimal type can store a Maximum of 65 Digits, with 30 digits after decimal point.

If Maximum Digits (or Precision) is not defined, It defaults to 10 and if Scale is not defined, it defaults to 0.

All basic calculations (+, -, *, /) with DECIMAL columns are done with a precision of 65 digits.

Help improve this page

Page status: No known problems

You can: