Solved

length in decimal

Posted on 2010-09-10
11
512 Views
Last Modified: 2012-05-10
does it include the period (.) also?

642418216.00
is this 11 or 12 bytes?

thanks
0
Comment
Question by:anushahanna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 3

Assisted Solution

by:ghayasurrehman
ghayasurrehman earned 40 total points
ID: 33649403
12 bytes
0
 
LVL 6

Author Comment

by:anushahanna
ID: 33649422
so, dot is always included?
0
 
LVL 16

Assisted Solution

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

use the below to determine the size
select LEN(642418216.00)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:gplana
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.

See this link for more information: http://msdn.microsoft.com/en-us/library/ms190476.aspx
0
 
LVL 6

Author Comment

by:anushahanna
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

by:anushahanna
ID: 33649696
in the link you provided
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

by:gplana
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

by:
Scott Pletcher 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 23

Assisted Solution

by:Snarf0001
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

by:parthmalhan
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

by:anushahanna
ID: 33661737
Thanks for correcting that. helped.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question