Re: cast numeric with scale and precision to numeric plain

From: Scott Bailey <artacus(at)comcast(dot)net>
To:
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: cast numeric with scale and precision to numeric plain
Date: 2009-10-22 01:05:06
Message-ID: 4ADFAFC2.1030604@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Sim Zacks wrote:
> I'm using 8.2.4
>
>
> Numeric with scale precision always shows the trailing zeros.
>
> Numeric plain only shows numbers after the decimal point that are being
> used.
>
>
> I would like to have the data in my table with scale and precision, but
> my views to be cast to numeric without any scale or precision.
>
> However, when I cast a numeric(16,4) to a ::numeric it doesn't cast it.
>
>
> In order to get the results I want, I have to cast it twice ::double
> precision::numeric and then it removes the trailing zeros.
>
>
> Is there any way to cast directly from numeric with scale and precision
> to plain numeric?

So you already got your answer about why it doesn't work the way you'd
like. But if you are just looking to format it for display you can use
to_char with the FM modifier.

SELECT f1, to_char(f1, 'FM999.0999')
FROM test;
15.0000 15.0
200.0040 200.004
12.4123 12.4123

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Patrick Brückner 2009-10-22 01:19:06 postgres doesn't start after crash
Previous Message Scott Marlowe 2009-10-22 00:31:51 Re: Linux TOP