By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,809 Members | 1,999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,809 IT Pros & Developers. It's quick & easy.

Silent truncation of numeric values.

P: n/a

Hi,

How come numeric(10,2) accepting value 10.011 and truncating the .001
part ? Shudnt' it be complaining , i am not sure.
Regds
Mallah.
tradein_clients=# CREATE TABLE t_a ( a numeric (10,2) );
CREATE TABLE
tradein_clients=#
tradein_clients=#
tradein_clients=# \d t_a
Table "public.t_a"
Column | Type | Modifiers
--------+---------------+-----------
a | numeric(10,2) |

tradein_clients=# INSERT INTO t_a values(10.01);
INSERT 50817524 1
tradein_clients=# INSERT INTO t_a values(10.011);
INSERT 50817525 1
tradein_clients=#
tradein_clients=#
tradein_clients=# SELECT * from t_a;
a
-------
10.01
10.01
(2 rows)

tradein_clients=#
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

On Sat, 22 Nov 2003, Rajesh Kumar Mallah wrote:
How come numeric(10,2) accepting value 10.011 and truncating the .001
part ? Shudnt' it be complaining , i am not sure.


AFAICS, the spec says that implementation-defined rounding or truncation
occurs if least significant digits would be lost. It appears to only be
an error if most significant digits would be lost.

For example:
If an assignment would result in a loss of the most significant digits,
an exception condition is raised. If least significant digits are lost,
implementation-defined rounding or truncating occurs with no exception
condition being raised.

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.