# Numeric types v15

Numeric types consist of four-byte integers, four-byte and eight-byte floating-point numbers, and fixed-precision decimals. The following table lists the available types.

Name | Storage size | Description | Range |
---|---|---|---|

`BINARY_INTEGER` | 4 bytes | Signed integer, alias for `INTEGER` | -2,147,483,648 to +2,147,483,647 |

`DOUBLE PRECISION` | 8 bytes | Variable-precision, inexact | 15 decimal digits precision |

`INTEGER` | 4 bytes | Usual choice for integer | -2,147,483,648 to +2,147,483,647 |

`NUMBER` | Variable | User-specified precision, exact | Up to 1000 digits of precision |

`NUMBER(p [, s ] )` | Variable | Exact numeric of maximum precision, `p` , and optional scale, `s` | Up to 1000 digits of precision |

`PLS_INTEGER` | 4 bytes | Signed integer, alias for `INTEGER` | -2,147,483,648 to +2,147,483,647 |

`REAL` | 4 bytes | Variable-precision, inexact | 6 decimal digits precision |

`ROWID` | 8 bytes | Signed 8 bit integer. | -9223372036854775808 to 9223372036854775807 |

## Integer types

The `BINARY_INTEGER`

, `INTEGER`

, `PLS_INTEGER`

, and `ROWID`

types store whole numbers (without fractional components) as specified in the numeric types table. Attempts to store values outside of the allowed range result in an error.

## Arbitrary precision numbers

The type `NUMBER`

can store an almost unlimited number of digits of precision and perform calculations exactly. We especially recommend it for storing monetary amounts and other quantities where exactness is required. However, the `NUMBER`

type is very slow compared to the floating-point types described in Floating point types.

The `scale`

of a `NUMBER`

is the count of decimal digits in the fractional part, to the right of the decimal point. The `precision`

of a `NUMBER`

is the total count of significant digits in the whole number, that is, the number of digits to both sides of the decimal point. So the number 23.5141 has a precision of 6 and a scale of 4. Integers have a scale of zero.

You can configure both the precision and the scale of the `NUMBER`

type. To declare a column of type `NUMBER`

, use the syntax:

The precision must be positive, and the scale must be zero or positive. Alternatively, this syntax selects a scale of 0:

Specifying `NUMBER`

without any precision or scale creates a column in which you can store numeric values of any precision and scale, up to the implementation limit on precision. A column of this kind doesn't coerce input values to any particular scale, whereas `NUMBER`

columns with a declared scale coerce input values to that scale. (The SQL standard requires a default scale of 0, that is, coercion to integer precision. For maximum portability, it's best to specify the precision and scale explicitly.)

If the precision or scale of a value is greater than the declared precision or scale of a column, the system attempts to round the value. If the value can't be rounded to satisfy the declared limits, an error occurs.

## Floating-point types

The data types `REAL`

and `DOUBLE PRECISION`

are *inexact*, variable-precision numeric types. In practice, these types are usually implementations of IEEE Standard 754 for Binary Floating-Point Arithmetic (single and double precision, respectively), to the extent that the underlying processor, operating system, and compiler support it.

Inexact means that some values can't be converted exactly to the internal format and are stored as approximations, so that storing and printing back out a value might show slight discrepancies. Managing these errors and how they propagate through calculations is the subject of an entire branch of mathematics and computer science and isn't discussed further here, except for the following points:

If you require exact storage and calculations (such as for monetary amounts), use the

`NUMBER`

type instead.If you want to do complicated calculations with these types for anything important, especially if you rely on certain behavior in boundary cases (infinity, underflow), evaluate the implementation carefully.

Comparing two floating-point values for equality might not work as expected.

On most platforms, the `REAL`

type has a range of at least `1E-37`

to `1E+37`

with a precision of at least six decimal digits. The `DOUBLE PRECISION`

type typically has a range of around `1E-307`

to `1E+308`

with a precision of at least 15 digits. Values that are too large or too small cause an error. Rounding might occur if the precision of an input number is too high. Numbers too close to zero that you can't represent as distinct from zero cause an underflow error.

EDB Postgres Advanced Server also supports the SQL standard notations `FLOAT`

and `FLOAT(p)`

for specifying inexact numeric types. Here, `p`

specifies the minimum acceptable precision in binary digits. EDB Postgres Advanced Server accepts `FLOAT(1)`

to `FLOAT(24)`

as selecting the `REAL`

type and `FLOAT(25)`

to `FLOAT(53)`

as selecting `DOUBLE PRECISION`

. Values of `p`

outside the allowed range draw an error. `FLOAT`

with no precision specified is taken to mean `DOUBLE PRECISION`

.