Re: How to truncate? integers - Mailing list pgsql-novice

From Steve Crawford
Subject Re: How to truncate? integers
Date
Msg-id 4EC426EB.8000500@pinpointresearch.com
Whole thread Raw
In response to How to truncate? integers  (Johann Schatzer <schatzer.johann@gmail.com>)
List pgsql-novice
On 11/16/2011 12:26 PM, Johann Schatzer wrote:
> How can I ~truncate~ integers?
>
>
> this column
>
> 4770
> ...
>
> should give
>
> 4700
> ...
>
> thank you

Oh, you can also use the behavior of integer math:

select (4770/100)*100;
  ?column?
----------
      4700

If you have negative numbers, you need to determine how they should be
truncated. The two methods will behave differently:

select (-4770/100)*100;
  ?column?
----------
     -4700


select floor(-4770*.01)*100;
  ?column?
----------
     -4800

Cheers,
Steve


pgsql-novice by date:

Previous
From: Steve Crawford
Date:
Subject: Re: How to truncate? integers
Next
From: Yangyang
Date:
Subject: How can I show more potential query plans, other than the default one?