Re: Rounding Float Array

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: Alex Magnum <magnum11200(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Rounding Float Array
Date: 2015-09-21 10:16:27
Message-ID: 20150921101627.GA9195@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Sep 21, 2015 at 11:55:23AM +0200, Alex Magnum wrote:
> Hello,
>
> I have a float array holding geo location information.
>
> geoloc
> -----------------------------------
> {5.3443133704554,100.29457569122}
> {5.3885574294704,100.29601335526}
> {3.1654978750403,101.60915851593}
> {5.3766154817748,100.31472444534}
> {3.1545014704258,101.70036971569}
> (5 rows)
> Is there an easy way to round all values to 4 decimals.

Sure:
$ select geoloc from alex;
geoloc
-----------------------------------
{5.3443133704554,100.29457569122}
{5.3885574294704,100.29601335526}
{3.1654978750403,101.60915851593}
{5.3766154817748,100.31472444534}
{3.1545014704258,101.70036971569}
(5 rows)

(depesz(at)[local]:5960) 12:15:46 [depesz]
$ select geoloc::numeric(8,4)[] from alex;
geoloc
-------------------
{5.3443,100.2946}
{5.3886,100.2960}
{3.1655,101.6092}
{5.3766,100.3147}
{3.1545,101.7004}
(5 rows)

depesz

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Kretschmer 2015-09-21 10:27:17 Re: Rounding Float Array
Previous Message Andreas Kretschmer 2015-09-21 10:08:19 Re: Rounding Float Array