Re: Most significant digit number formatting

From: Berend Tober <btober(at)seaworthysys(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Most significant digit number formatting
Date: 2005-11-17 16:29:08
Message-ID: 437CAFD4.9070805@seaworthysys.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


codeWarrior wrote:

>If it is a numeric data column -- you probably want to use the "round"
>function:
>
>SELECT round(1200.01, 3);
>SELECT round(12.009, 2);
>
>
>
Interesting. I had tried that. After your message I tried again and
encountered this interesting anomaly: while the ROUND function used in a
query run in the SQL window of PgAdmin III does in fact force output of
trailing zero decimal digits to the extent specified, i.e.,

SELECT
project_number,
labor_hours,
TO_CHAR(labor_hours, '999.999'),
ROUND(labor_hours,3)
FROM time_data
LIMIT 5

"05-08",1974.0000," ###.###",1974.000
"05-100",10810.5000," ###.###",10810.500
"05-125",285.0000," 285.000",285.000
"05-150",404.5000," 404.500",404.500
"05-200",44.0000," 44.000",44.000

Running the same query though a TQuery dataset object in Borland Delphi
using the BDE truncates the trailing zeros from ROUND:

000-05-08 1974 ###.### 1974
000-05-100 10810.5 ###.### 10810.5
000-05-125 285 285.000 285
000-05-150 404.5 404.500 404.5
000-05-200 44 44.000 44

That is why I didn't realize ROUND was an option, but for me it still is
not since the report is produced by a Delphi application. I suppose I
can accomplish this formatting programmatically within the Delphi
application, but I was hoping to have the data base do it directly.

Thanks,
Berend Tober

>"Berend Tober" <btober(at)seaworthysys(dot)com> wrote in message
>news:4379F997(dot)6050703(at)seaworthysys(dot)com(dot)(dot)(dot)
>
>
>>Say I want to format calculated numeric output to uniformly have a
>>specific number of decimal places,
>>
...

Attachment Content-Type Size
btober.vcf text/x-vcard 233 bytes

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Rysdam 2005-11-17 16:31:27 Re: Very slow queries on 8.1
Previous Message David Rysdam 2005-11-17 16:28:42 Re: Very slow queries on 8.1