G
Guest
I am writing a function in VBA to implement an algorithm that my company
uses. This algorithm takes the input, multiplies the number by a certain
factor (1.025 in this case), and then truncates the number to the tenth
place. This process is repeated TableUp number of times. Below is the code
I am using:
Public Function TableChange(OriginalRate As Double, TableUp As Long) As Double
If TableUp = 1 Then
TableChange = Int(OriginalRate * 1.025 / 0.1) * 0.1
Else
TableChange = Int(TableChange(OriginalRate, TableUp - 1) * 1.025 /
0.1) * 0.1
End If
End Function
With a seed of OriginalRate = 83.1 and TableUp = 7, this function works
correctly until the last iteration where the value the function returns is
98.3, but should be 98.4.
I believe the error comes from the Int function or possibly data type
changes, but I do not know enough, to say definitely. Can anyone help me
with the cause of this loss of value? Thank you very much.
I am using Access 2000.
uses. This algorithm takes the input, multiplies the number by a certain
factor (1.025 in this case), and then truncates the number to the tenth
place. This process is repeated TableUp number of times. Below is the code
I am using:
Public Function TableChange(OriginalRate As Double, TableUp As Long) As Double
If TableUp = 1 Then
TableChange = Int(OriginalRate * 1.025 / 0.1) * 0.1
Else
TableChange = Int(TableChange(OriginalRate, TableUp - 1) * 1.025 /
0.1) * 0.1
End If
End Function
With a seed of OriginalRate = 83.1 and TableUp = 7, this function works
correctly until the last iteration where the value the function returns is
98.3, but should be 98.4.
I believe the error comes from the Int function or possibly data type
changes, but I do not know enough, to say definitely. Can anyone help me
with the cause of this loss of value? Thank you very much.
I am using Access 2000.