dbTalk Databases Forums  

part Integer and decimal

comp.database.oracle comp.database.oracle


Discuss part Integer and decimal in the comp.database.oracle forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Wallace
 
Posts: n/a

Default part Integer and decimal - 06-30-2005 , 03:25 AM






What's the code PL/sql for find the part integer end decimal of number?
Thanks



Reply With Quote
  #2  
Old   
Hilarion
 
Posts: n/a

Default Re: part Integer and decimal - 06-30-2005 , 08:04 AM






Quote:
What's the code PL/sql for find the part integer end decimal of number?
In Oracle8i use TRUNC function to get the integer part:

TRUNC( a )
eg.:
TRUNC( +2.5 ) == +2
TRUNC( -2.5 ) == -2

and combine it with oryginal number to get fractional part:

a - TRUNC( a )
eg.:
(+2.5) - TRUNC( +2.5 ) == 2.5 - 2 = 0.5
(-2.5) - TRUNC( -2.5 ) == -2.5 + 2 = -0.5

or create new function:

CREATE FUNCTION FRACT( num IN NUMBER ) RETURN NUMBER DETERMINISTIC AS
BEGIN
RETURN num - TRUNC( num );
END;

FRACT( +2.5 ) == +0.5
FRACT( -2.5 ) == -0.5


Newer versions of Oracle can allready have function acting like above FRACT.

Hilarion


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.