DBAsupport.com Forums - Powered by vBulletin
Results 1 to 7 of 7

Thread: A simple question

  1. #1
    Join Date
    Jun 2001
    Location
    Helsinki. Finland
    Posts
    3,938
    Consider:

    SQL> select to_number(3/10) from dual;

    TO_NUMBER(3/10)
    ---------------
    .3

    Now, you want to see 0.30, not .3. What is the easiest way?


  2. #2
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,684
    This works:

    select to_char(to_number(3/10), '0.00') from dual;
    Tim...
    OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
    OCA PL/SQL Developer
    Oracle ACE Director
    My website: oracle-base.com
    My blog: oracle-base.com/blog

  3. #3
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,684
    Or this:

    COLUMN amount FORMAT '0.00';
    select to_number(3/10) as amount from dual;
    Tim...
    OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
    OCA PL/SQL Developer
    Oracle ACE Director
    My website: oracle-base.com
    My blog: oracle-base.com/blog

  4. #4
    Join Date
    Jun 2001
    Location
    Helsinki. Finland
    Posts
    3,938
    Originally posted by TimHall
    This works:

    select to_char(to_number(3/10), '0.00') from dual;
    Thanks Tim but I do neither need the result for SQL*Plus nor I want it to be a varchar2 (other people will sum the values of all columns, so string's noo good).

    Something else in mind?


  5. #5
    Join Date
    Nov 2001
    Location
    New Brunswick, NJ
    Posts
    67
    This is kinda hokey, but how about

    select rpad(lpad(to_number(3/10),3,0),4,0) as RESULT from dual

    Paul

  6. #6
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    Originally posted by julian
    I do neither need the result for SQL*Plus nor I want it to be a varchar2 (other people will sum the values of all columns, so string's noo good).
    Julian, this is totaly client-side settings problem, not an Oracle isue. Different client environments will display numeric results in different ways. For example, my SQL*Plus displays your result as ".3", while my TOAD displays the same result as "0.3". If your client allows you to set display options fror numeric values, then you can do it (like Tim suggested for SQL*Plus), otherwise you'll have to convert to string and manipulate it from there. Oracle merely returns the correct numeric results, it is clients choice how to represent it.
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

  7. #7
    Join Date
    Jun 2001
    Location
    Helsinki. Finland
    Posts
    3,938
    otherwise you'll have to convert to string and manipulate it from there.
    I am afraid that's what I have to do. I have made a function which calculates the accured interests of bonds. Since a person might pocess more than one bond at a time, when reporting the bond statistics, we want to show the sum of all accured interests so that numbers such as .78 are displayed as 0.7800

    And you are right, this is not an Oracle issue but rather a client enviroment one.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width