Home » SQL & PL/SQL » SQL & PL/SQL » get the decimal value
get the decimal value [message #32385] Mon, 16 August 2004 02:25 Go to next message
subhasish
Messages: 33
Registered: May 2000
Member
my requirement is as follow..

work hours in numbers are like

13.16
11.23
11.09
0
11.1
13.06
11.2
11
12.08
11.01
13

I want to get the decimal values
like
16
23
9
0
1
6
2
0
8
1
0

thanks in advance
Re: get the decimal value [message #32388 is a reply to message #32385] Mon, 16 August 2004 02:54 Go to previous messageGo to next message
Venkat
Messages: 110
Registered: February 2001
Senior Member
the below query prints fractional part of a salary column of emp table

select decode(instr(sal,'.'),0,0,substr(sal,instr(sal,'.')+1)) from emp
Re: get the decimal value [message #32390 is a reply to message #32388] Mon, 16 August 2004 03:23 Go to previous messageGo to next message
Ultra
Messages: 98
Registered: November 2003
Member
select
nvl(
rtrim(100000000000000000000000*(sal-round(sal)),0)
,0)
from emp

(doesn't work if the number of decimal
is to big, but it's not dependant of
the number format)
Re: get the decimal value [message #32391 is a reply to message #32385] Mon, 16 August 2004 03:33 Go to previous messageGo to next message
Art Metzer
Messages: 2480
Registered: December 2002
Senior Member
How are you going to tell the difference between 11.2 and 11.02, since it appears from your examples that you would want both values to return 2?

Given your data, here are two columns; one of what I think your result should be, and one of what you asked for.
SQL> CREATE TABLE t (hours NUMBER);
 
Table created.
 
SQL> INSERT INTO t VALUES (13.16);
SQL> INSERT INTO t VALUES (11.23);
SQL> INSERT INTO t VALUES (11.09);
SQL> INSERT INTO t VALUES (0);
SQL> INSERT INTO t VALUES (11.1);
SQL> INSERT INTO t VALUES (13.06);
SQL> INSERT INTO t VALUES (11.2);
SQL> INSERT INTO t VALUES (11);
SQL> INSERT INTO t VALUES (12.08);
SQL> INSERT INTO t VALUES (11.01);
SQL> INSERT INTO t VALUES (13);
SQL> SELECT t.hours
  2  ,      MOD(t.hours * 100,100)                               should_be
  3  ,      DECODE(MOD(t.hours * 100,100)
  4         ,      0, 0
  5         ,      TO_NUMBER(RTRIM(TO_CHAR(MOD(t.hours * 100
  6                                        ,   100))
  7                          ,     '0')))                        you_asked_for
  8  FROM   t
  9  /
 
     HOURS  SHOULD_BE YOU_ASKED_FOR
---------- ---------- -------------
     13.16         16            16
     11.23         23            23
     11.09          9             9
         0          0             0
      11.1         10             1
     13.06          6             6
      11.2         20             2
        11          0             0
     12.08          8             8
     11.01          1             1
        13          0             0
 
11 rows selected.
 
SQL>
Let's be careful out there.

Art.
Re: get the decimal value [message #32393 is a reply to message #32385] Mon, 16 August 2004 03:49 Go to previous messageGo to next message
Venkat
Messages: 110
Registered: February 2001
Senior Member
prints fractional part of the sal column in emp table

select sal-floor(sal) from emp
Re: get the decimal value [message #32394 is a reply to message #32385] Mon, 16 August 2004 03:57 Go to previous message
Venkat
Messages: 110
Registered: February 2001
Senior Member
to fractional part of sal column in emp table

select replace(sal-floor(sal),'.') from emp;
Previous Topic: HOW to USE TOUCH COMMAND (UNIX) FROM PL/SQL
Next Topic: Viewing Oracle BLOB
Goto Forum:
  


Current Time: Thu Aug 07 23:42:14 CDT 2025