Variable Declaration Problem?

  • Thread starter Thread starter Anthony Viscomi
  • Start date Start date
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
 
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.
 
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top