Re: numeric rounding - Mailing list pgsql-general

From James Moe
Subject Re: numeric rounding
Date
Msg-id auto-000000650502@sohnen-moe.com
Whole thread Raw
In response to numeric rounding  (Gezeala 'Eyah' "Bacuño" II <gezeala25@yahoo.com>)
List pgsql-general
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 29 Sep 2003 00:47:05 -0700 (PDT), Gezeala 'Eyah' \"Bacu±o\" II wrote:

>i have a plpgsql function where in i compute numeric values for my php scripts..
>my problem is my function just won't round some numbers properly.
>
  What do you mean by "properly?" How, exactly, do you want the numbers rounded? What
about negative numbers?
  There is a round() function that offers various options. I do not know how it handles
negative numbers, though.
  For money numbers I found this to be a reasonable method:

  sign = (0.0 <= N) ? 1 : -1;
  tmp  = abs(N);
  tmp  = round((tmp + 0.005), 2);
  N    = tmp * sign;


- --
jimoe at sohnen-moe dot com
pgp/gpg public key: http://www.keyserver.net/en/
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 5.0 OS/2 for non-commercial use
Comment: PGP 5.0 for OS/2
Charset: cp850

wj8DBQE/eHV9sxxMki0foKoRAnitAJ4yd1LG4eBlNpsQL3tFLqera9JRQACg3rKX
LnDwRQkyga6uxBzeEjEX+qE=
=LIzc
-----END PGP SIGNATURE-----





pgsql-general by date:

Previous
From: Josh Berkus
Date:
Subject: Re: [SQL] Conditional row grained + FK dependency oriented lazy replication
Next
From: Robert Treat
Date:
Subject: Re: Postgres vs. Progress performance