Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Decimals rounding without wanting them too.

Discussion in 'Information Technology' started by Tdahlman, Jul 28, 2006.

  1. Tdahlman

    Tdahlman
    Expand Collapse
    Guest

    I have a table and I'm supposed to be entering quantities of fabric being
    used and these quantities are decimals. But it just keeps rounding. I don't
    know why and I have to fix it because it becomes part of a pricing equation.
    Please Help.
    Thanks in Advance.
    Travis
     
  2. Loading...

    Similar Threads Forum Date
    Controversy Surrounding Nanakshahi Sikh Calender Sikh Sikhi Sikhism Dec 3, 2009
    Controversy Surrounding Prof Darshan Singh Ji Hard Talk Nov 14, 2009

  3. fredg

    fredg
    Expand Collapse
    Guest

    On Wed, 12 Jul 2006 12:18:01 -0700, Tdahlman wrote:

    > I have a table and I'm supposed to be entering quantities of fabric being
    > used and these quantities are decimals. But it just keeps rounding. I don't
    > know why and I have to fix it because it becomes part of a pricing equation.
    > Please Help.
    > Thanks in Advance.
    > Travis


    Usually it's because the field's datatype has incorrectly been set to
    Number, Integer Field Size.
    An Integer, by definition is a whole number and cannot have a decimal
    part.
    Change the Field size property to single or double.
    --
    Fred
    Please respond only to this newsgroup.
    I do not reply to personal e-mail
     
  4. Albert D.Kallal

    Albert D.Kallal
    Expand Collapse
    Guest

    Welcome to computers, and decimal math!!!

    Take the following code in ms-access

    Public Sub TestAdd()


    Dim MyNumber As Single
    Dim i As Integer


    For i = 1 To 10
    MyNumber = MyNumber + 1.01
    Debug.Print MyNumber
    Next i
    End Sub


    Here is the actual output of the above:


    1.01
    2.02
    3.03
    4.04
    5.05
    6.06
    7.070001
    8.080001
    9.090001
    10.1


    You can see that after just 7 additions..already rounding is occurring

    and if we add the following line of code to the end of the above:

    if MyNumber = 10.1 = True then
    msgbox "the number is 10.1"
    else
    msgbox "the number is somthing else"
    endif


    The above will actual produce:

    the number is something else

    What the above means that decimal numbers represented in a computer are only
    a approximation. The solution is to user integer numbers, or in the case of
    financial calculations, use currency data type. (the currency data type is a
    actually a scaled integer,a nd it fakes the decimal repression by
    representation integer..and moving the decimal point).

    Try changing your data types to currency, and that should cure your rounding
    problems...

    --
    Albert D. Kallal (Access MVP)
    Edmonton, Alberta Canada
    pleaseNOOSpamKallal@msn.com
    http://www.members.shaw.ca/AlbertKallal
     
  5. Jamie Collins

    Jamie Collins
    Expand Collapse
    Guest

    Albert D.Kallal wrote:
    > Try changing your data types to currency, and that should cure your rounding
    > problems...


    Or indeed to the DECIMAL data type e.g. the OP hasn't specified but the
    values involved may have more than four decimal places.

    Personally, I'd find it confusing to encounter a schema that modelled
    fabric quantities as CURRENCY.

    Changing the data type to currency may introduce other more subtle
    rounding issues. The CURRENCY type rounds values using a banker's
    rounding algorithm, which may not be appropriate to fabric quantities.
    The DECIMAL type truncates and therefore may be the way to go if the
    aim truly is to eliminate rounding.

    Jamie.

    --
     
  6. Albert D.Kallal

    Albert D.Kallal
    Expand Collapse
    Guest

    I had a rather large, and perhaps heated debate/exchange on this issue
    recently...

    I come around a bit on this issue. So, I do now accept that using decimal
    type is a reasonable choice here.....

    > the OP hasn't specified but the
    > values involved may have more than four decimal places.


    Yes, the above is likely the deal breaker issue here. (my guess is .25, .5.
    75 etc...but, we really don't know the lengths involved)

    >
    > Personally, I'd find it confusing to encounter a schema that modelled
    > fabric quantities as CURRENCY.


    That is another fair point. However, support in ms-access is better for
    currency data types.

    There are pros/cons, and not knowing if any rounding is needed makes this
    decision a toss up right now......

    --
    Albert D. Kallal (Access MVP)
    Edmonton, Alberta Canada
    pleaseNOOSpamKallal@msn.com
    http://www.members.shaw.ca/AlbertKallal
     
  7. Jamie Collins

    Jamie Collins
    Expand Collapse
    Guest

    Albert D.Kallal wrote:
    > I come around a bit on this issue. So, I do now accept that using decimal
    > type is a reasonable choice here.....
    >
    > support in ms-access is better for
    > currency
    >
    > There are pros/cons, and not knowing if any rounding is needed makes this
    > decision a toss up right now......


    In the same spirit, I thank you for presenting a balanced view.

    Jamie.

    --
     

Share This Page