• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3386
  • Last Modified:

Float VS Decimal for storing percentages in SQL 2005

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
KimberleyY
Asked:
KimberleyY
2 Solutions
 
Aneesh RetnakaranDatabase AdministratorCommented:
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
 
LowfatspreadCommented:
for any business related processing you should always use NUMERIC or DECIMAL  data types
as FLOAT data types are too inaccurate..

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

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now