Обсуждение: casting float8 type

Поиск
Список
Период
Сортировка

casting float8 type

От
Bob Dusek
Дата:
Hello everyone,

I apologize if this seems elementary to you, but I just spent quite a
bit of time searching the archives and the documentation for a way to do
this.  I may have been looking wrong, but I tried to look in all of the
"obvious" places. Anyway...

How would I go about converting a value of type 'float8' to a value of
type 'int'?  It's probably not possible to do a straight conversion of a
float to an int, but is there a truncate, or a rounding function that I
could use?  I couldn't find such a thing in my search.

Thanks in advance,

Bob

Re: [GENERAL] casting float8 type

От
Ulf Mehlig
Дата:
Bob Dusek <bobd@palaver.net> wrote:

> How would I go about converting a value of type 'float8' to a value
> of type 'int'?  It's probably not possible to do a straight
> conversion of a float to an int, but is there a truncate, or a
> rounding function that I could use?  I couldn't find such a thing in
> my search.

in a table/class `tbl' with an float attribute `fl' of my 6.3.2 database,
the following works:

    select cast(fl as int4) from tbl;

Hope it helps!

Ulf

--
======================================================================
 %%%%%            Ulf Mehlig              <ulf.mehlig@uni-bremen.de>
   %%%%!%%%       Projekt "MADAM"         <umehlig@uni-bremen.de>
%%%% %!% %%%%     ----------------------------------------------------
 ---| %%%         MADAM:  MAngrove    |  Center for Tropical Marine
    ||--%!%              Dynamics     |  Biology
    ||                  And           |  Fahrenheitstrasse 1
 _ /||\_/\_            Management     |
/  /    \  \ ~~~~~~~~~~~~~~~~~        |  28359 Bremen/Germany
  ~~~~~~~~~~~~~~~~~~~~

Re: [GENERAL] casting float8 type

От
Bob Dusek
Дата:
Thank you Ulf,

It works perfectly (so far :-)

Thanks a lot,

Bob

Ulf Mehlig wrote:
>
> Bob Dusek <bobd@palaver.net> wrote:
>
> > How would I go about converting a value of type 'float8' to a value
> > of type 'int'?  It's probably not possible to do a straight
> > conversion of a float to an int, but is there a truncate, or a
> > rounding function that I could use?  I couldn't find such a thing in
> > my search.
>
> in a table/class `tbl' with an float attribute `fl' of my 6.3.2 database,
> the following works:
>
>     select cast(fl as int4) from tbl;
>
> Hope it helps!
>
> Ulf
>
> --
> ======================================================================
>  %%%%%            Ulf Mehlig              <ulf.mehlig@uni-bremen.de>
>    %%%%!%%%       Projekt "MADAM"         <umehlig@uni-bremen.de>
> %%%% %!% %%%%     ----------------------------------------------------
>  ---| %%%         MADAM:  MAngrove    |  Center for Tropical Marine
>     ||--%!%              Dynamics     |  Biology
>     ||                  And           |  Fahrenheitstrasse 1
>  _ /||\_/\_            Management     |
> /  /    \  \ ~~~~~~~~~~~~~~~~~        |  28359 Bremen/Germany
>   ~~~~~~~~~~~~~~~~~~~~