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

1 - About

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

numeric is generally functionally identical to decimal.

3 - Syntax


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

where:

  • p is the precision (the total number of significant digits)
  • f is scale (the number of digits at the right side of the point)

4 - Example

  • The number 00123456.780 has a precision of 8 and a scale of 2

5 - 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>.

6 - 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>

7 - Documentation / Reference


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap