Decimal datatype in sql server 2000

The decimal data type in sql server 2000 has precision and scale.

The precision defines how many length of chars that can exist from left to right including the the numbers after the decimal point.

For example col1 decimal(3,2) can contain total of 3 numbers. 9.20 is valid whereas 99.2 is invalid because sql server will add a zero at end to make it 99.20 and that invalidates the rule of precision 3.

try this

drop table testDec2

create table testDec2(col1 decimal(8,2))

insert into testDec2 values (999996.9999999)
--number on left is of len 6 and even thogh we have 7 digits after decimal point, sql -- will truncate the number to insert 999997.00 . Notice the rounding.

-- if you try to insert 999999.99 it wont work because of rounding. The number will
-- be 1000000.00 i.e. total of 9 chars.

select * from testDec2

give it a try. ;-)

Comments

Popular posts from this blog

Making text bold in Adobe Acrobat

Java Keytool Export Private Key, PKCS#12 or .p12 export or conversion from java keystore