numeric and float converts to int differently? - Mailing list pgsql-sql

From SZŰCS Gábor
Subject numeric and float converts to int differently?
Date
Msg-id 072c01c39d65$65f83950$0403a8c0@fejleszt4
Whole thread Raw
Responses Re: numeric and float converts to int differently?
List 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 -------------------------------



pgsql-sql by date:

Previous
From: Joe Conway
Date:
Subject: Re: connectby
Next
From: Stephan Szabo
Date:
Subject: Re: bug in working with TEXT constants ?