[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:
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...
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!?
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.
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?
Re: Whole numbers and rounding up or down?
VB uses what so called "Banker's rounding" so I'm not quite sure what you mean by "different for each program" ... :confused:
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:
Dim j As Double
j = 35040.24
j = Round(j / 100) * 100 ' Returns 35000
j = 35070.24
j = Round(j / 100) * 100 ' Returns 35100
Does that help?