Re: Simple math statement - problem

From: "Gregory Williamson" <Gregory(dot)Williamson(at)digitalglobe(dot)com>
To: "Postgres User" <postgres(dot)developer(at)gmail(dot)com>, "pgsql-general" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Simple math statement - problem
Date: 2007-11-30 05:37:30
Message-ID: 8B319E5A30FF4A48BE7EEAAF609DB233015E2FF1@COMAIL01.digitalglobe.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

The question:
>
> How can I write statements that returns a decimal?
>
>
billing=# select 1/100;
?column?
----------
0
(1 row)

As you said ...

So make everything decimal:
billing=# select 1.0/100.0;
?column?
------------------------
0.01000000000000000000

Or:
billing=# select 1::decimal/100::decimal;
?column?
------------------------
0.01000000000000000000

I think that when you use integers you lose precision right out the gate. Others can provide better insight I hope ...

HTH,

Greg Williamson
Senior DBA
GlobeXplorer LLC, a DigitalGlobe company

Confidentiality Notice: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information and must be protected in accordance with those provisions. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.

(My corporate masters made me say this.)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gregory Williamson 2007-11-30 05:47:44 Re: Simple math statement - problem
Previous Message Ow Mun Heng 2007-11-30 05:36:11 Re: Simple math statement - problem