views:

3136

answers:

4

I'm trying to figure out decimal data type of a column in the SQL server. I need to be able to store values like 15.5, 26.9, 24.7, 9.8, etc

I assigned decimal(18, 0) to the column data type but this not allowing me to store these values. What is the right way to do this?

Thank you

+11  A: 

DECIMAL(18,0) will allow 0 digits after the decimal point.

Use something like DECIMAL(18,4) instead that should do just fine!

Marc

marc_s
For clarification DECIMAL(18,4) is 14 digits before the decimal point and 4 digits after the decimal point.
R. Bemrose
Right - total of 18 digits, 4 of which after the decimal point - exactly right.
marc_s
+1  A: 

decimal(m,a)

m is the number of total digits your decimal can have, while a is the max number of decimal points you can have.

http://www.tsqltutorials.com/datatypes.php has descriptions for all the datatypes.

DForck42
A: 

The other answerers are right. Assuming your examples reflect the full range of possibilities what you want is DECIMAL(3, 1). Or, DECIMAL(14, 1) will allow a total of 14 digits. It's your job to think about what's enough.

Matthew Flaschen
+1  A: 

the settings for Decimal are its precision and scale or in normal language, how many digits can a number have and how many digits do you want to have to the right of the decimal point.

so if you put pi into a Decimal(18,0) it will be recorded as 3

if you put pi into a decimal(18,2) it will be recorded as 3.14

if you put pi into Decimal(18,10) be recorded as 3.1415926535