Float VS Decimal for storing percentages in SQL 2005

Posted on 2006-05-16
Last Modified: 2009-06-17
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?

Question by:KimberleyY
    LVL 75

    Assisted Solution

    by:Aneesh Retnakaran
    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;

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


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    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.

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now