Float

  • Hi all,

    Is it necessary to give precision and scale for float datatype? Our data will need to have four places to right of decimal, it needs to be float. Do I have to create with float(precision) or just float?

    Thanks much

  • FLOAT is just that FLOAT. - precise to 15 digits or something like that. You may get some oddities after calculations - such as 0.999999999999999 where you expected 1.0

    FLOAT(x) specifies the number of bits to use in storing the data. if x is 24 its 8-bytes and 15 digit accuracy

    if you need a specific precision you can use

    DECIMAL(totaldigits,decimals) - this will always be accurate.

    MONEY is good for 4 decimal places

  • psangeetha (5/21/2009)


    Our data will need to have four places to right of decimal, it needs to be float.

    [font="Verdana"]You use FLOAT (or REAL) when your data has a varying number of decimal places. If you have a fixed number of decimal places, use DECIMAL (or NUMERIC).

    There are some numbers that FLOAT cannot represent. 0.3, for example. This can cause all sorts of interesting rounding errors. Also, when you combine FLOAT values of widely different precision, you can get... er... interesting results.

    So if you know you have a fixed number of decimal places, don't use FLOAT... use DECIMAL.

    [/font]

  • Bruce W Cassidy (5/21/2009)


    psangeetha (5/21/2009)


    Our data will need to have four places to right of decimal, it needs to be float.

    [font="Verdana"]There are some numbers that FLOAT cannot represent. 0.3, for example. This can cause all sorts of interesting rounding errors. Also, when you combine FLOAT values of widely different precision, you can get... er... interesting results.

    So if you know you have a fixed number of decimal places, don't use FLOAT... use DECIMAL.

    [/font]

    Some years ago they gave a project for an invoicing system. All amounts stored in FLOAT... *sigh*

  • Float stores the data as binary numbers, and this causes problems in applications where there needs to be an exact base 10 representation. Many base 10 fractions have no exact representation, so float is usually a poor choice for common business applications dealing with money or other numeric fractions.

    select 0.3E as ZeroPointThree

    Results:

    ZeroPointThree

    -----------------------------------------------------

    0.29999999999999999

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply