numeric and float converts to int differently?
От | SZŰCS Gábor |
---|---|
Тема | numeric and float converts to int differently? |
Дата | |
Msg-id | 072c01c39d65$65f83950$0403a8c0@fejleszt4 обсуждение исходный текст |
Ответы |
Re: numeric and float converts to int differently?
|
Список | 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 по дате отправления: