Re: Rounding

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: "Chris Boget" <chris(at)wild(dot)net>, "PGSql Novice" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Rounding
Date: 2003-10-03 17:20:05
Message-ID: 200310031020.05015.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Chris,

> Is there a way, internal in PG, that you can round to the
> nearest half decimal (rounded up or down)? ie, I want to
> round 97.37 to 97.5 or 97.81 to 98.
> The closest thing I could see in the docs would take the
> 97.33 turning it into 97.4 and 97.81 to 97.8. Is there some-
> thing I am missing?

No, but you could easily write your own function. For example:

CREATE FUNCTION round_to_half ( NUMERIC )
RETURNS NUMERIC AS '
SELECT (ROUND(($1 * 2))) / 2;
' LANGUAGE SQL IMMUTABLE STRICT;

--
Josh Berkus
Aglio Database Solutions
San Francisco

In response to

  • Rounding at 2003-10-03 15:26:11 from Chris Boget

Browse pgsql-novice by date

  From Date Subject
Next Message Nabil Sayegh 2003-10-03 17:23:03 Re: plperl db crash
Previous Message M. Bastin 2003-10-03 16:39:39 cancel request in progress