Variable Declaration Problem?

A

Anthony Viscomi

Here is an excerpt from my code:

Dim intCalcMin As Integer

If Me.Pr_Type.Value = 2 And Me.TxtMinPriceCalc < Me.Min_Price Then
intCalcMin = Me.Min_Price.Value * Me.PctTotal.Value
Me.txtHolder.Value = intCalcMin + Me.Min_Price
Me.txtSubTotal.Value = Me.txtHolder.Value * Me.Quantity.Value
End If

My problem is that the variable (intCalcMin) seems to be rounding the
number.

Example:
Min_Price = 40.00
PctTotal = -0.09
thus the intCalcMin should = -3.6, but it keeps showing -4.0

Any ideas?
Thanks in advance!
Anthony Viscomi
 
D

Dirk Goldgar

Anthony Viscomi said:
Here is an excerpt from my code:

Dim intCalcMin As Integer

If Me.Pr_Type.Value = 2 And Me.TxtMinPriceCalc < Me.Min_Price Then
intCalcMin = Me.Min_Price.Value * Me.PctTotal.Value
Me.txtHolder.Value = intCalcMin + Me.Min_Price
Me.txtSubTotal.Value = Me.txtHolder.Value * Me.Quantity.Value
End If

My problem is that the variable (intCalcMin) seems to be rounding the
number.

Example:
Min_Price = 40.00
PctTotal = -0.09
thus the intCalcMin should = -3.6, but it keeps showing -4.0

Any ideas?
Thanks in advance!
Anthony Viscomi

An integer is by definition a whole number, so when declare a variable
as type Integer (or Long, which is shorthand for "Long Integer"), you
get a variable that can only hold whole numbers. Hence the calculation
results are rounded to a whole number when you assign them to the
variable.

Use one of the floating-point types -- Single or Double -- instead; or,
if you need precision with up to four decimal places, you can use the
Currency data type.
 
A

Anthony Viscomi

Perfect...Thanks!
Dirk Goldgar said:
An integer is by definition a whole number, so when declare a variable
as type Integer (or Long, which is shorthand for "Long Integer"), you
get a variable that can only hold whole numbers. Hence the calculation
results are rounded to a whole number when you assign them to the
variable.

Use one of the floating-point types -- Single or Double -- instead; or,
if you need precision with up to four decimal places, you can use the
Currency data type.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Top