Results 1 to 4 of 4
  1. #1
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    192

    Rnd Function

    I want to display 4 numbers between 7.8 and 8.1, that is 7.8 or 7.9, 8.0 or 8.1



    I tried the RND function. However, it is not giving the result I need. Tried various combinations.

    Need help for the correct syntax.

    Thanks,
    Alex

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    What did you try and what results did you get?
    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

  3. #3
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    192
    Thanks isladogs. I solved by a clue given in an Excel tutorial.

    The syntax is:

    Round(Rnd() * 0.3 + 7.8, 1)

    Multiplying by the difference and adding by the lowest and rounded to 1 decimal place.

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Whilst that may work for you, the expression isn't strictly correct.
    The general expression to return a random integer is Int((upperbound-lowerbound+1)*Rnd+lowerbound)
    See https://www.w3schools.com/sql/func_msaccess_rnd.asp for an explanation.

    Obviously that needs to be modified as you don't want integer values

    You should also use the line Randomize beforehand to ensure the 'seed' is reset each time...or you may get the same number sequence every time you run this.
    Finally, for info the Round function works differently in Excel and Access
    However, the difference only applies to how 'mid-point numbers' such as 1.55, 1.65 are handled so won't matter in your case.
    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: 15
    Last Post: 10-17-2018, 09:26 PM
  2. Replies: 15
    Last Post: 05-31-2017, 02:10 PM
  3. Replies: 2
    Last Post: 02-26-2017, 11:31 AM
  4. Replies: 8
    Last Post: 11-04-2014, 10:44 PM
  5. Replies: 8
    Last Post: 01-31-2014, 01:45 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