Storing a number with exactly two decimal places [message #373396] |
Fri, 13 April 2001 13:24 |
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 |
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;
|
|
|
|