numeric and float converts to int differently?

From: SZŰCS Gábor <surrano(at)mailbox(dot)hu>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: numeric and float converts to int differently?
Date: 2003-10-28 15:08:51
Message-ID: 072c01c39d65$65f83950$0403a8c0@fejleszt4
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2003-10-28 15:11:51 Re: bug in working with TEXT constants ?
Previous Message Joe Conway 2003-10-28 15:04:03 Re: [SQL] connectby