Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Cents to Dollars

Status
Not open for further replies.

PLSQL2000

Programmer
Jun 1, 2009
1
Hello,

I'm trying to convert cents to dollars, i.e add a decimal place. The problem I've encountered is that when the cents value is in hundreds, i.e. 100 cents = 1.00, it drops the .00 and just shows 1.

Below is an example of how I'm trying to do this... Is there a better way to do this?

Code:
set serveroutput on;
declare
  test1 number;
  test2 number;
begin
  test1 := 234;
  test1 := round(test1/100, 2);
  test2 := 200;
  test2 := round(test2/100, 2);
  dbms_output.put_line(test1);
  dbms_output.put_line(test2);
end;

This is the result I get:

Code:
anonymous block completed
2.34
2

Note I want it show this:

Code:
anonymous block completed
2.34
2.00
 
Put number formatting in the output statement(s) as shown below. Adjust to suit.

Code:
set serveroutput on;
declare
  test1 number;
  test2 number;
begin
  test1 := 234;
  test1 := round(test1/100, 2);
  test2 := 200;
  test2 := round(test2/100, 2);
  dbms_output.put_line(test1);
  dbms_output.put_line(TO_CHAR(test2,'99.99'));
end;

yields an output of:-

Code:
2.34
  2.00

Regards

T
 
or:

set serveroutput on;
declare
test1 number;
test2 number;
begin
test1 := 234.0;
test1 := round(test1/100, 2);
test2 := 200;
test2 := round(test2/100, 2);
dbms_output.put_line(test1);
dbms_output.put_line(test2);
--dbms_output.put_line(TO_CHAR(test2,'99.99'));
end;



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top