Re: Fwd: error in the example given for numeric data types

From: "Peter J(dot) Holzer" <hjp-pgsql(at)hjp(dot)at>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Fwd: error in the example given for numeric data types
Date: 2023-07-15 21:19:05
Message-ID: 20230715211905.lih3wsmwsccgk4rx@hjp.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2023-07-15 12:08:26 +0530, Priyank Rajvansh wrote:
> Page: https://www.postgresql.org/docs/15/datatype-numeric.html
> Description:
>
> article 8.1.2 states the following:
>
> ''We use the following terms below: The precision of a numeric is the total
> count of significant digits in the whole number, that is, the number of
> digits to both sides of the decimal point. The scale of a numeric is the
> count of decimal digits in the fractional part, to the right of the decimal
> point. So the number 23.5141 has a precision of 6 and a scale of 4. Integers
> can be considered to have a scale of zero.''
>
> however it also states the following towards the end:
>
> '' For example, a column declared as
>
> NUMERIC(3, 5)
> will round values to 5 decimal places and can store values between -0.00999
> and 0.00999, inclusive.''
>
> Now from whatever i could decipher the syntax of the numeric data type is
> NUMERIC(precision,scale) and if we write NUMERIC (3,5) it would mean that we
> are trying to store a number which has 3 digits in total and 5 of them are
> to the right of the decimal point, which doesn't make sense !

It may sound weird but it does make sense. There are three digits in the
number and the rightmost of them is five positions to the right of the
decimal pointis. So you can store

0.00999
--12345

but not

0.01000
--12345

as that would need a fourth digit
and also not
0.000123
--123456
as not the rightmost digit is now six places right of the decimal
point.

Mathematically you store an integer with 3 digits and multiply it with
10^-5 to get the value.

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp(at)hjp(dot)at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2023-07-16 15:35:48 Re: Installation Issue
Previous Message Daniel Gallo 2023-07-15 21:11:22 Re: Rocky Linux 9 and postgres10