length in decimal

does it include the period (.) also?

is this 11 or 12 bytes?

Who is Participating?
Scott PletcherConnect With a Mentor Senior DBACommented:
For decimal columns, the physical storage is based on the *total* digits (precision):

Precision Storage bytes
1 - 9         5
10-19       9
20-28     13
29-38     17

So, decimal(9, <whatever>) takes 5 bytes, decimal(10, <whatever>) takes 9 bytes, etc..

The decimal point is not stored per se.  Decimals are stored in an internal format -- you don't really have to worry abou the details of that.
ghayasurrehmanConnect With a Mentor Commented:
12 bytes
anushahannaAuthor Commented:
so, dot is always included?
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

vdr1620Connect With a Mentor Commented:
Its 12..

use the below to determine the size
select LEN(642418216.00)
But understand that decimal is a variable-length datatype. So this number is 12 byte width, but other number could be less or more bytes, depending on the number of digits.

See this link for more information: http://msdn.microsoft.com/en-us/library/ms190476.aspx
anushahannaAuthor Commented:

>>this number is 12 byte width, but other number could be less

you  mean 6424.26 is 6 bytes and 11.1 is 3 bytes, right?
anushahannaAuthor Commented:
in the link you provided

it says int is 4 bytes only - is it because it lacks the decimal point and hence less storage used, as compared to the decimal?

gplanaConnect With a Mentor Commented:
int last 4 bytes because uses binary encoding, and uses the int as is encoded on the machine. You can represent any integer nmber from -2^31 to +2^31-1. So in total they are 2^32 which are the possible combinations on a 32 bits integer (i.e. 4 bytes).
Decimal packs decimal digits. On this encoding you need 4 bits for every digit, so you can represent 2 digits on a byte.This is the theory, but you need some extra bytes to know how long is the data, as it's a variable width datatype
Hope it helps.
Snarf0001Connect With a Mentor Commented:
Scott is completely correct, the number you indicated takes 9 bytes to store, not 11 or 12.

>> select LEN(642418216.00)

will NOT return the actual data storage length, it returns the number of characters.
To return the actual storage size, use DATALENGTH()

select DATALENGTH(642418216.00)
Parth MalhanConnect With a Mentor Principal EngineerCommented:
Decimal is not included

if the datatype of a field is numeric(5,2)
its can contain atmost (999.99) value

Decimal point s not included in numeric

But if you are using varchar(5)
then decimal is also counted
so value may 33333
or 333.3
or 99.99 etc
anushahannaAuthor Commented:
Thanks for correcting that. helped.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.