Solved

# length in decimal

Posted on 2010-09-10
508 Views
does it include the period (.) also?

642418216.00
is this 11 or 12 bytes?

thanks
0
Question by:anushahanna

LVL 3

Assisted Solution

ghayasurrehman earned 40 total points
ID: 33649403
12 bytes
0

LVL 6

Author Comment

ID: 33649422
so, dot is always included?
0

LVL 16

Assisted Solution

vdr1620 earned 40 total points
ID: 33649445
Its 12..

use the below to determine the size
select LEN(642418216.00)
0

LVL 15

Expert Comment

ID: 33649606
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.

0

LVL 6

Author Comment

ID: 33649687
OK.

>>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?
0

LVL 6

Author Comment

ID: 33649696
http://msdn.microsoft.com/en-us/library/ms190476.aspx

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?

thanks
0

LVL 15

Assisted Solution

gplana earned 40 total points
ID: 33649868
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.
0

LVL 69

Accepted Solution

ScottPletcher earned 167 total points
ID: 33650876
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.
0

LVL 22

Assisted Solution

Snarf0001 earned 160 total points
ID: 33650942
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)
0

LVL 4

Assisted Solution

parthmalhan earned 53 total points
ID: 33652333
Decimal is not included

if the datatype of a field is numeric(5,2)
then
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
0

LVL 6

Author Comment

ID: 33661737
Thanks for correcting that. helped.
0

## Featured Post

### Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Auâ€¦
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties