Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2003
    Location
    Portugal
    Posts
    111

    Unanswered: A sum problem (2 decimal only)

    Some calculated fields give something like this:

    22507,397260274 -> shows 22507,40 (formated 2 decimal)
    374,794520547945 -> shows 374,79
    149,753424657534 -> shows 149,75
    ------------------------------ Sum: 23.031,95 when it couldt give 23.031,94

    Is there an idea to make it works?

    Thanks,

    Ruas

  2. #2
    Join Date
    Feb 2004
    Posts
    142
    Floating point calcs can be a bit of a pain. If I need to get results that actually use the rounded numbers before calculation I create a function that I embed into the query

    Public Function RoundIt_2(dblVarIn as double) as double
    On error resume next
    Roundit_2 = (dblVarIn*100)/100
    if err.number <> 0 then
    RoundIt_2 = dblVarIn
    end if
    End Function

    Usually works, if you expect that nulls might get into the function then trap them asnd return zero.
    KC

  3. #3
    Join Date
    Mar 2002
    Posts
    32

    Re: A sum problem (2 decimal only)

    Originally posted by jmruas
    Some calculated fields give something like this:

    22507,397260274 -> shows 22507,40 (formated 2 decimal)
    374,794520547945 -> shows 374,79
    149,753424657534 -> shows 149,75
    ------------------------------ Sum: 23.031,95 when it couldt give 23.031,94

    Is there an idea to make it works?

    Thanks,

    Ruas
    I added up your left column and got 23031.945205479479

    This rounds off to 23,031.95

    Looks like it sums fine.

  4. #4
    Join Date
    Jul 2003
    Location
    Portugal
    Posts
    111
    Yes, Ben, it sums fine

    But, as the result is shown with 2 decimal and the sum isn't, then we have a good sum (23,031.95), with a bad result(23,031.94)!

    Now I'll try the function sent by AZ KC (thank you!)...

    Thank you

    Ruas
    Last edited by jmruas; 03-03-04 at 15:24.

  5. #5
    Join Date
    Feb 2004
    Posts
    142
    i forgot to include the most important piece this morning

    Cint(somedouble*100)/100 this will round to two places.

    Sorry about that.

    Place this either in the query (Some Alias: roundIt_2([fieldValue]) or if you are using a calculated textbox =roundit_2(your calc) or if in a procedure ReturnVal = roundIt_2(proc results)
    KC

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •