Re: strip zeros from fractional part

From: Tony Wasson <ajwasson(at)gmail(dot)com>
To: "Giovanni M(dot)" <drayah(at)gmail(dot)com>
Cc: Mike Nolan <nolan(at)gw(dot)tssi(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: strip zeros from fractional part
Date: 2005-10-03 19:32:10
Message-ID: 6d8daee30510031232o49f8d75cp3bbabf29ab49d362@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 10/3/05, Giovanni M. <drayah(at)gmail(dot)com> wrote:
> Round and trunc dont provide the functionality I need.
>
> Say for example I have two values in a column of type numeric as follows:
> 23.455
> 12.300
>
> What I need to happen is stripping the "useless" zeros in the
> fractional part of numbers so 12.300 would become 12.3 and 23.455
> would stay the same
>
> Round and trunc can´t do this without me first checking if the number
> can indeed be "rounded" to a number without losing its precise value

As a workaround, you could try using the trim function. You'd need to
cats your numbers to text strings, but it looks like it will drop
useless 0's for you.

test=# SELECT trim(trailing 0 FROM '12.300'::TEXT)::NUMERIC;
rtrim
-------
12.3
(1 row)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Fernando Grijalba 2005-10-03 19:34:57 Re: Help with inventory control - Thank You!
Previous Message Giovanni M. 2005-10-03 19:14:02 Re: strip zeros from fractional part