Juventus tech
Juventus tech

Reputation: 95

What is the purpose of using digits while declaring DECIMAL datatype in SQL Server?

I recently used a datatype

decimal(5,2)

I read about it but not clear. What is the purpose of using 5,2 in it ?

Why my variable is only storing numbers like this 134.56 etc but not 143678.9088

And why it rounds my number ? I don't want to round but need exact figure

Upvotes: 0

Views: 51

Answers (2)

Rahul Tripathi
Rahul Tripathi

Reputation: 172408

As answered by Ako, 5 is the total number of digits that can be stored (including the decimals) and 2 is the number of decimal places.

The number is rounded off at the specified maximum length and number of decimal places.

i don't want to round but need exact figure

In that case, you need to increase the length of your decimal datatype. You need to ascertain the maximum number of decimal places your data can have and then define your column length accordingly.

Read more here on MSDN about Decimal

Upvotes: 2

Ako
Ako

Reputation: 1221

5 is total length, 2 is number of decimals. So the max that you can store is 999.99

Upvotes: 1

Related Questions