Results 1 to 5 of 5

Thread: [resolved]Whole numbers and rounding up or down?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    18

    Resolved [resolved]Whole numbers and rounding up or down?

    I've managed to get VB to create and calculate an 'offer' which will be calculated 4 or 5 times throughout the program. The 'offer' nearly always has a decimal place which i dont need, i just want a whole number returned and preferably rounded up or down to the nearest 100.

    I've tried:
    VB Code:
    1. offer = CStr(Left$(offer, 2)) & "00"

    but this only works with (say) 3,500 but not 35,000 - on the larger numbers it reduces them to 4 figures! but the random offer could be anywhere from 3 figures to 6 figures!


    This...
    VB Code:
    1. offer = Round(offer - 2)

    seems to work a bit better but will not give 'to the nearest 100' results.

    any idea how to get the best of both worlds!?
    Last edited by nick_roberts; Dec 11th, 2005 at 06:56 PM.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Getting Rid Of A Decimal Place?

    Title and message body are contadicting each other: it's easy enough to Get Rid Of A Decimal Place by using Int() or Fix() functions without rounding up, with rounding use CInt() or CLng() or Format() instead. To round to the nearest 100 however you'd need to write your own logic.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    18

    Re: Getting Rid Of A Decimal Place?

    Well, i suppose i have got rid of the decimal place with help from this site, but then i cam across this problem.

    I take it from that the rounding to the nearest 100 is different for each program?

  4. #4

  5. #5
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: [resolved]Whole numbers and rounding up or down?

    I'm not quite sure what you're trying to do, but this will round to the nearest 100
    VB Code:
    1. Dim j As Double
    2.    
    3.     j = 35040.24
    4.     j = Round(j / 100) * 100    ' Returns 35000
    5.    
    6.     j = 35070.24
    7.     j = Round(j / 100) * 100    ' Returns 35100
    Does that help?
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

Posting Permissions

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



Click Here to Expand Forum to Full Width