|
-
Apr 2nd, 2003, 01:20 PM
#1
Thread Starter
Fanatic Member
Rounding Up and Down Conditionally
I have a need to do conditional rounding. I need to check to see if a variable is an integer. If it is, do nothing BUT if it's not, round down to the next whole number. How can I check to see if a variable is an integer? Thanks, Jeremy
He who listens well, speaks well.
-
Apr 2nd, 2003, 01:32 PM
#2
Use the Int() function, i.e.
-
Apr 2nd, 2003, 01:51 PM
#3
Re: Rounding Up and Down Conditionally
Originally posted by JCScoobyRS
How can I check to see if a variable is an integer?
VB Code:
If Var = Int(Var) Then
MsgBox "It Is"
Else
MsgBox "It Isn't"
End If
Has someone helped you? Then you can Rate their helpful post. 
-
Apr 2nd, 2003, 02:01 PM
#4
Note that what Aaron is getting at doesn't actually check whether the number is an integer or not, it just converts it to one. If you only want to round DOWN in every case (11.9 goes to 11), then this, or n\1 (integer divide by one) will work. If you want to do more than just round the value and end up with an integer, then manovo11 has got a better solution.
-
Apr 2nd, 2003, 02:19 PM
#5
Thread Starter
Fanatic Member
So this:
VB Code:
PPS = 1 / ItemRec!PS_QTY_P
PPS = Int(PPS)
where PPS = 17.125 doesn't round down to 17? How would I modify this to do that? Thanks, Jeremy
He who listens well, speaks well.
-
Apr 2nd, 2003, 03:47 PM
#6
-
Apr 2nd, 2003, 03:51 PM
#7
Member
If you do
and then do
what is PPS set to at the end? Is it returning 17, or 18, or what? What type of variable do you have PPS dimmed as?
-
Apr 2nd, 2003, 04:31 PM
#8
Thread Starter
Fanatic Member
Here is the code:
VB Code:
Private Sub Get_MHPricing(ByVal lngVvIndex As Long)
'Get Pricing for Hardware/Materials
If ItemRec2!IM_PROD_CODE = "M" Then
Dim PPS As Double
Dim SC As Long
If ItemRec!PS_QTY_P = 0 Then
PPS = 1
Else
PPS = 1 / ItemRec!PS_QTY_P
PPS = Int(PPS)
End If
If txtQuantity(lngVvIndex).Text < PPS Then
SC = 1
Else
SC = CLng(((txtQuantity(lngVvIndex).Text + 2) / PPS) + 0.49)
End If
txtMaterial(lngVvIndex).Text = txtMaterial(lngVvIndex).Text + ((SC * ItemRec2!IM_COST) / txtQuantity(lngVvIndex).Text)
ElseIf ItemRec2!IM_PROD_CODE = "H" Then
Dim QPQ As Single
QPQ = ItemRec!PS_QTY_P * txtQuantity(lngVvIndex).Text
If ItemRec2!IM_J_QTY1 = 0 Then
txtHardware(lngVvIndex).Text = ItemRec!PS_QTY_P * ItemRec2!IM_COST
Else
If QPQ < ItemRec2!IM_J_QTY1 Then
txtHardware(lngVvIndex).Text = txtHardware(lngVvIndex).Text + (ItemRec!PS_QTY_P * ItemRec2!IM_COST)
ElseIf QPQ >= ItemRec2!IM_J_QTY1 And QPQ < ItemRec2!IM_J_QTY2 Then
txtHardware(lngVvIndex).Text = txtHardware(lngVvIndex).Text + (ItemRec!PS_QTY_P * ItemRec2!IM_PRICES1)
ElseIf QPQ >= ItemRec2!IM_J_QTY2 And QPQ < ItemRec2!IM_J_QTY3 Then
txtHardware(lngVvIndex).Text = txtHardware(lngVvIndex).Text + (ItemRec!PS_QTY_P * ItemRec2!IM_PRICES2)
ElseIf QPQ >= ItemRec2!IM_J_QTY3 And QPQ < ItemRec2!IM_J_QTY4 Then
txtHardware(lngVvIndex).Text = txtHardware(lngVvIndex).Text + (ItemRec!PS_QTY_P * ItemRec2!IM_PRICES3)
ElseIf QPQ >= ItemRec2!IM_J_QTY4 And QPQ < ItemRec2!IM_J_QTY5 Then
txtHardware(lngVvIndex).Text = txtHardware(lngVvIndex).Text + (ItemRec!PS_QTY_P * ItemRec2!IM_PRICES4)
ElseIf QPQ >= ItemRec2!IM_J_QTY5 Then
txtHardware(lngVvIndex).Text = txtHardware(lngVvIndex).Text + (ItemRec!PS_QTY_P * ItemRec2!IM_PRICES5)
End If
End If
End If
End Sub
Thanks, Jeremy
He who listens well, speaks well.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|