Solved

# Float VS Decimal for storing percentages in SQL 2005

Posted on 2006-05-16
3,357 Views
I see that some people use float to store percentages and some use decimal. When storing percenatges in a table what are the pros and cons of each?  Is one method better?   Is decimal better because it is an exact number?

Thanks!
0
Question by:KimberleyY

LVL 75

Assisted Solution

floats store numbers as base 2, decimals as base 10.

try this example ( i got it from one website)

create table Test111
(NumDecimal decimal(10,4)
, numFloat float
);

insert into Test111 (NumDecimal, numFloat) values (0.1, 0.1);
insert into Test111 (NumDecimal, numFloat) values (0.3, 0.3);
insert into Test111 (NumDecimal, numFloat) values (0.25, 0.25);
insert into Test111 (NumDecimal, numFloat) values (1.0/3.0, 1.0/3.0);
insert into Test111 (NumDecimal, numFloat) values (1.0/6.0, 1.0/6.0);

select * from test111;

select numdecimal*3 , numfloat*3 from test111;

drop table Test111;

0

LVL 50

Accepted Solution

for any business related processing you should always use NUMERIC or DECIMAL  data types
as FLOAT data types are too inaccurate..

0

## Featured Post

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.