function calculation error

Results 1 to 2 of 2

Thread: function calculation error

  1. #1
    Join Date
    Dec 1969

    Default function calculation error

    I have function that calculates an investment return on a daily basis, as follows:<BR><BR>&#060;%<BR>Function CalcReturn(LastTrade,TradeEntry)<BR><BR>Dim StockReturn<BR><BR>If TradeEntry = 0 Then<BR> StockReturn = 0<BR>Else<BR> StockReturn = ((LastTrade - TradeEntry) / TradeEntry)<BR>End If<BR><BR>CalcReturn = StockReturn<BR><BR>End Function<BR><BR>%&#062;<BR><BR>LastTrade comes from a database type money.<BR>TradeEntry comes from a database type money.<BR>Output is to a database field of type float.<BR><BR>This is an example of some data<BR><BR>LastTrade TradeEntry Output <BR>33.78 29.91 0.12938816449348<BR>39.65 29.70 0.335016835016835<BR>39.46 38.23 3.21736855872352E-04 * incorrect<BR>14.289 10.52 0.358269961977186<BR><BR>When i run this function the 1st 2nd and 4th outputs are correct but the third one is off, <BR>can anyone give me an idea as to why this is.<BR><BR>Thanks in advance for your help.<BR><BR>Zac

  2. #2
    Join Date
    Dec 1969

    Default by 100...

    3.217E-04 should be 3.217E-02, of course.<BR><BR>Might I suggest you try converting the numbers from the DB to double before doing the calcs? Use the CDBL function.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts