From: | Ow Mun Heng <Ow(dot)Mun(dot)Heng(at)wdc(dot)com> |
---|---|
To: | Postgres User <postgres(dot)developer(at)gmail(dot)com> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Simple math statement - problem |
Date: | 2007-11-30 05:36:11 |
Message-ID: | 1196400971.29502.0.camel@neuromancer.home.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, 2007-11-29 at 21:22 -0800, Postgres User wrote:
> I have a large function that's doing a number of calcs. The final
> return value is wrong for a simple reason: any division statement
> where the numerator is less than the denominator is returning a zero.
>
> Each of these statements return a 0, even when properly cast:
>
> select 1/100
> select Cast(1 / 100 As decimal)
> select Cast(1 / 100 As numeric(6,2))
>
> How can I write statements that returns a decimal?
>
select (1::numeric/100::numeric)
same as if you do a 1.0/100.0
>
> The problem doesn't appear to be that Postgres won't return decimal
> values, as these statements return the correct value:
>
> select .01
> select Cast(.01 As decimal)
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
From | Date | Subject | |
---|---|---|---|
Next Message | Gregory Williamson | 2007-11-30 05:37:30 | Re: Simple math statement - problem |
Previous Message | Postgres User | 2007-11-30 05:22:01 | Simple math statement - problem |