Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Difference between Decimal,Float,Double in terms of exact calculation

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 735
    Comment on it

    Difference between float,double and decimal in terms of exact calculation(Tested in mysql)

    I was creating an application where I need exact values from mysql procedure so I have to find better data type which gives me exact value so I tested it first and observe that for addition decimal works better but for divison double/float give you exact value for some extent (float for only 8 points) and (double upto 15 points)

    Here is the test I did in mysql database:

    create table test(float<em>number float,double</em>number double(15,2),decimal<em>number decimal(15,2));
    create table test</em>result(float<em>number float,double</em>number double(15,2),decimal_number decimal(15,2));
    insert into test values(123,123,123);
    insert into test values(123.23,123.23,123.23);
    insert into test values(500000.23,500000.23,500000.23);
    insert into test values(500000.29,500000.29,500000.29);
    insert into test values(500000.99,500000.99,500000.99);
    insert into test<em>result select float</em>number/2, double<em>number/2,decimal</em>number/2 from test;
    select * from test_result;
    

    Take a calculator and match the test_results table with them.

    Hope this helps :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: