# Easy Question: Best DataType for "31.2"

I have percentages I want to use in SQL Server.  The format I want is ##.#, so example numbers are...

10 (or 10.0)
12.5
8.4
35.6
and,
100 (or 100.0)

The numbers will be positive, never more than 1 decimal is needed, and the number will always between 0 and 100.

What is my best datatype to use for such numbers?  I could use a smallint, and multiply by 100 to get the precision I want.  Or do I want to use a float, real, decimal, numeric, etc?  Obviously I want to use as few bytes as possible and have this data still fully storable, and functioning as numbers.
LVL 1
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
decimal(4,1)
Commented:
You should use decimal(4,1). Your largest number from your example is 100, so I use a precision of 4 and a scale of 1 - since you only want one decimal place).

Decimal and numeric are data types that capture exact numbers. Float and real are used to capture approximate numbers.

Author Commented:
Thanks LandyJ.  Can you explain a tiny bit more.  How many bytes will that consume?  I don't exactly understand the decimal format and how many bytes it uses.  It's easy with a smallint because it always consumes 2 bytes.
Commented:
Sorry, quick on the draw.  Didn't fully catch the "few bytes as possible" part.  To expand my answer a little:

decimal(4,1) will cost you 5 bytes.  Smallint will only be 2 in storage, but you have the extra calculations:
declare @pct decimal(4,1)
SET @pct = @smallintfld / 100

Plus, other considerations are that a decimal(4,1) will do auto rounding.  @pct = 99.958 will end up being 100.0.  If you were going to do that anyway, you're all set.  If you want 99.9, you have to do some other number gymnastics.

Experts Exchange Solution brought to you by