Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2012
    Posts
    72

    VBA - Randomize/Rnd issue with whole numbers.

    I'm having trouble getting a random number procedure to work in that I want it to display a random number between two numbers with the output displaying two decimal points. Such as:

    Range: 7.35 - 7.45.

    I've tried a couple of things like:

    Code:
    Int((Upperbound - Lowerbound + 1) * Rnd + Lowerbound)
    , replacing the +1 with, say, .01, .1, 0.1, etc.

    The issue is it always displays a whole number without decimals. Even if I have the textbox set to display 2 decimal points and a standard number it displays 7.00, 6.00, etc.

    What am I doing wrong?

    Thank you!

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Integers are whole numbers. They can only ever represent whole numbers. If you try to cast a decimal to an integer, it will drop the fraction.

    You want to be working with a decimal instead.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    12,436
    if your range is 7.35 - 7.45.
    then
    Code:
    dim MyRandomNumber as double
    MyRandomNumber = (Int((745 - 735 + 1) * Rnd + 735) )/ 100
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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