Home » RDBMS Server » Server Administration » Storing a number with exactly two decimal places
Storing a number with exactly two decimal places [message #373396] Fri, 13 April 2001 13:24 Go to next message
tedagem
Messages: 3
Registered: April 2001
Junior Member
Hello, I need to store a numeric value so that there are always two decimal places. E.g. "31" gets stored as "31.00".

How do I set up my create table statement to ensure that all inserted values are in the correct format?
Re: Storing a number with exactly two decimal places [message #373398 is a reply to message #373396] Fri, 13 April 2001 16:07 Go to previous messageGo to next message
Andrew again...
Messages: 270
Registered: July 2000
Senior Member
Oracle won't store insignificant digits, the format picture is used to format the output.

-- precison 5, 2 decimals
create table a1 (col1 number(5,2));

-- insignificant precision is ignored
insert into a1 values (1);
insert into a1 values (2.);
insert into a1 values (3.0);
insert into a1 values (4.00);

-- highest precision
insert into a1 values (123.45);

-- too big - won't go
insert into a1 values (1234.22);

-- rounded down to 2 decimals
insert into a1 values (234.44444444);

-- rounded up to 2 decimals
insert into a1 values (345.55555555);

select * from a1;

column col1 number 999.99
select * from a1;

column col1 number 999.9999999
select * from a1;
Re: Storing a number with exactly two decimal places [message #373399 is a reply to message #373396] Fri, 13 April 2001 17:04 Go to previous message
tedagem
Messages: 3
Registered: April 2001
Junior Member
Well that would explain why I couldn't figure out how to do it...

Thanks for your help.
Previous Topic: Storing a number with exactly two decimal places
Next Topic: Re: dynamic SQL and DBMS_SQL
Goto Forum:
  


Current Time: Mon Dec 23 09:44:57 CST 2024