From: SZŰCS Gábor <surrano@mailbox.hu>
To: pgsql-sql@postgresql.org
Subject: numeric and float converts to int differently?
Date: Tue, 28 Oct 2003 16:08:51 +0100
Message-ID: <072c01c39d65$65f83950$0403a8c0@fejleszt4> (raw)
Dear Gurus,
I'm using PostgreSQL 7.3.3.
I was wondering if this is undefined, intentional or to be changed/fixed in
the future. See the snippit at the end of this mail.
QUESTION 1: Is it intentional that converting 0.5 to int4
- from numeric: rounds *away from* zero
- from float: rounds *towards* zero (tried float4 and float8 too)?
QUESTION 2: Is it safe to assume it won't change (haven't changed) in the
upcoming versions?
QUESTION 3: Is there a function or conversion method that converts 0.5
according to
- mathematical rules (*up*)
- accounting rules (*down*, at least here in Hungary)?
TIA,
G.
------------------------------- cut here -------------------------------
# select int4('0.5'::numeric);
1
# select int4('-0.5'::numeric);
-1
# select int4('0.5'::float);
0
# select int4('-0.5'::float);
0
------------------------------- cut here -------------------------------
What I would really like to see:
# select round_math('0.5');
1
# select round_math('-0.5');
0
# select round_acct('0.5');
0
# select round_acct('-0.5');
-1
------------------------------- cut here -------------------------------
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: surrano@mailbox.hu
Subject: Re: numeric and float converts to int differently?
In-Reply-To: <072c01c39d65$65f83950$0403a8c0@fejleszt4>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox