SQL - Decimal(p,s) or Numeric(p,s)

Data System Architecture

About

DECIMAL and NUMERIC are sql datatype used to represent a fixed point notation (exact number)

numeric is generally functionally identical to decimal.

Example

With a DECIMAL(5,2):

  • the number has:
    • a precision of 5
    • and a scale of 2
  • you would be able to store any value with:
  • values can be stored in the range from -999.99 to 999.99.

The number 00123456.780 has:

  • a precision of 8 (ie 12345678)
  • and a scale of 2 (ie 78)

Syntax

NUMERIC(p, s)
DECIMAL(p, s)

where:

Numeric vs Decimal

The Sql standard defined NUMERIC and DECIMAL in the following words:

  • NUMERIC specifies the data type exact numeric, with the decimal precision and scale specified by the <precision> and <scale>.
  • DECIMAL specifies the data type exact numeric, with the decimal scale specified by the <scale> and the implementation-defined decimal precision equal to or greater than the value of the specified <precision>.

Storage and range

Maximum storage sizes vary, based on the precision.

Precision Storage bytes
1 - 9 5
10-19 9
20-28 13
29-38 17

For a precision of 38, the range of value is <math>-10^{38 +1} </math> through <math>10^{38}</math>





Discover More
Data System Architecture
Computer - Fixed Point

fixed point number in computer are generally called: NUMERIC or DECIMAL
Data System Architecture
SQL - Data Type (Column Type)

The Data Type of a column in SQL. They are defined in the ANSI/ISO SQL standard but may vary from sql engine (database) to another. The below table shows you the history of the data type in the ANSI...
Data System Architecture
SQL - Timestamp Data Type

This page is the in Sql datatype. A TIMESTAMP contains the following s: YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND. If is not specified,...



Share this page:
Follow us:
Task Runner