Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2002
    Posts
    7

    Unanswered: A calculation field that can round-down

    I have an Excel spreadsheet that works out a result based on a time value and another standard integer. The only way to make this accurate is to round-down the result.

    I am trying to find a way of 'rounding down' in an Access '97 calculation field so I don't have to use Excel.

    Can anybody suggest anything?

  2. #2
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    when people say 'round down' they really mean convert to int ie chop off the data after the decimal point, so i would suggest you try CINT or something simalar depending on where your doing the calc or you may need to use integer division which is something like "34 Div 3"
    Last edited by m.timoney; 12-17-02 at 06:46.
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  3. #3
    Join Date
    Nov 2002
    Posts
    7
    Sorry to sound stupid- any chance you could show me some example VB code that would do what you're suggesting?

    I'm not sure I understand fully what you mean (CINT?).

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    a generalised function to round InNum DOWN to Dex decimal places where:
    Dex = +2: 99.9999 -> 99.99)
    Dex = -2: 9999.99 -> 9900)
    Dex = 0: 999.999 -> 999

    public function RDown(InNum as double, Dex as integer) as double
    RDown = (Int(InNum * 10^Dex))/10^Dex
    end function

    worry about (better: error check for) overflow if you are messing with big numbers.


    izy

  5. #5
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    sorry cint rounds int don't on positives, or you could use fixdoesn't round on negatives

    Sub test()
    MsgBox Int(38.765)
    MsgBox fix(-99.8)
    MsgBox Int(-99.8)
    End Sub

    Last edited by m.timoney; 12-17-02 at 08:17.
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  6. #6
    Join Date
    Nov 2002
    Posts
    7
    timoney-

    I tried that code, but unfortunately it rounds the figure UP if the decimal is over .5.

  7. #7
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    try again i've editted it, i hoped i caught it before you noticed
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  8. #8
    Join Date
    Nov 2002
    Posts
    7

    Thumbs up

    timoney- many thanks, that seems to do the trick. I owe you one!

Posting Permissions

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