Results 1 to 3 of 3
  1. #1
    nagiese is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2011
    Location
    Nashville, TN
    Posts
    43

    How to creat a custom roundup function in Access

    I need to create a custom roundup function that works exactly the same as the built-in ROUNUP function in Excel (ex. 98.37 rounds up to 99.00% in excel). I tried the following code but it always rounds up to 100%



    Code:
    Public Function roundup(number) As Long    If Int(number) < number Then
             roundup = Int(number) + 1
        Else
             roundup = number
        End If
    End Function
    How do I write this so a number like 98.37 or 98.01 rounds up to 99%, but I can't have any number over 100%.

    Thanks so much for your help.
    Nena

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    you need to be clear what your numbers and format are - you talk about 98.37 and 98.01 but then mention 99%/100%. to be 99% the number must be .9837 in which case the formula would be

    (int(number*100)+1)/100

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Here's a variation using the Fix function (which always rounds down)

    Code:
    Function RoundUp(Number) As Long
    
    If CInt(Number) = Number Then
        RoundUp = Number
    Else
        RoundUp = Fix(Number) + 1
    End If
    
    
    End Function
    NOte this assumes you are working with numbers like 98.37 not calculated % based on e.g. 98.37/100 - same point as ajax made really
    Last edited by isladogs; 04-26-2018 at 06:33 PM. Reason: Modified to fix error in code
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 11-07-2017, 01:52 AM
  2. Replies: 4
    Last Post: 09-29-2017, 09:05 AM
  3. Custom Function: how to add Where Clause
    By PeakH in forum Modules
    Replies: 3
    Last Post: 09-19-2017, 10:13 AM
  4. Now Function Custom Format
    By DrJohn in forum Access
    Replies: 9
    Last Post: 03-16-2016, 09:51 AM
  5. update query with inner join roundup
    By tmcrouse in forum Access
    Replies: 2
    Last Post: 04-01-2015, 12:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums