Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

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?

2 Answers

0 votes
by (40.7k points)

If you use, DECIMAL(18,0) it’ll allow 0 digits after the decimal point.

Instead of DECIMAL(18,0)use DECIMAL(18,4) because it’ll give you 18 digits, in which 4 digits will come after the decimal point and 14 digits will come before the decimal point.

0 votes
by (1.5k points)

In SQL, to store decimal values, DECIMAL or NUMERIC data types will help. Functionally they both are the same.

DECIMAL(precision, scale)

Precision: total number of digits for a number.

Scale: Number of digits after decimal point.

Example: 

DECIMAL(8,2)

So a number like 234512.13 can go with the format.

Related questions

0 votes
1 answer
0 votes
2 answers
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...