Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3374
  • 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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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