I’m doing some calculations on VB based on values returned from a database, I’ve compared the values to the results I’m already getting on MS Excel and they seem to a bit off. I also know all the data is being read succesfully from the database. I’m wondering if it could have something to do with the data types I’m using? I’ve tried with both double and decimal and still no luck. There are 24 values in each array. My formula is:
Σ[(forecast-historic)/historic*100]/24
This is my code, all the variables are doubles by the way:
Public Function Evaluate(ByVal historic() As Double, ByVal forecast() As Double) As Double
For z As Integer = 0 To 23
hourly(z) = ((forecast(z) - historic(z)) / historic(z)) * 100
daily+= Math.Abs(hourly(z))
Next
effectiveness= daily / 24
Return effectiveness
End Function
For example if:
historic() = {16,18,15,16,14,14,15,16,17,20,22,25,27,27,27,27,26,24,23,22,19,18,16,16}
forecast() = {17,17,16,16,16,16,16,15,15,18,21,24,26,27,29,29,28,28,26,24,22,21,19,18}
The result on MS Excel is 8.47643, while on VB it is 9.1245.
I’ve checked the values 1 by 1, and they differ since the first operations when I send the value to hourly.
Any suggestions on how to make this more exact? Thanks.
For the example value you provided, VB value 9.1245 seems correct. I tried in excel and got result as 9.12452077.
Check your excel spreadsheet formulas..