Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rounding numbers up 2

Status
Not open for further replies.

storer

Programmer
Mar 27, 2000
41
0
0
US
I have a report where I would like a number, which is the result of a calculated field, to always round up. If the answer is 8, I would like the report to read "8". If the answer is 8.3, I would like the report to read "9". Currently, 8.3 rounds down to 8 and 8.6 rounds up to 9. Thanks for your help!
 
Hi,
I haven't tested this code yet, but you may want to try it anyway.

'place in the OnFormat event for the section ...
' where it will be printed
Dim intRemainder as integer
'mod function will return the remainder after ...
' dividing txtFieldValue by the number after "mod"
' Of course, dividing by 1 will always get the ...
' fractional remainder
intRemainder = txtFieldValue Mod 1
If intRemainder > 0 Then
txtFieldValue = txtFieldValue + 1
End If

You will need to see if the original 8.3 becomes 9, or does it become 9.3. If it is 9.3, then a little modification to the formula is called for.
HTH, [pc2]
Randy Smith
California Teachers Association
 
hmmmmm, this sounds like a similar problem PBricker helped me with...try this:

MyRoundedNumber: Int([NumField]) + Iif([NumField] - Int([NumField]) > 0,1,0)

Essentially what this does is cuts off the remainder (using INT) then adds 1 if the remainder is greater than 0, or adds 0 if remainder is 0.

Good Luck
[yinyang]
 
You can use this formula.

MyroundedNumber: -1 * Int(-1 * [NumberField])


The Int() of a Negative number is lower so Int(-123.45) equals -124 * -1 = 124
It works for both positive and negative numbers.

Paul

 
Sorry shannonp1 I missed your post when I went to respond to this. That will do it also.

Paul
 
Is 'ok' PaulBricker, your solution...again...is much shorter/better though :)
[yinyang]
 
Thanks for your help! It works great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top