Re: How to truncate? integers

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Johann Schatzer <schatzer(dot)johann(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: How to truncate? integers
Date: 2011-11-16 21:11:07
Message-ID: 4EC426EB.8000500@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Richard Broersma 2011-11-16 21:25:22 Re: How to truncate? integers
Previous Message Steve Crawford 2011-11-16 21:07:50 Re: How to truncate? integers