Results 1 to 3 of 3

Thread: Calculations always wrong?

  1. #1

    Thread Starter
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    I'm writing an app which is kind of a small payroll system that calculates NI but not tax. I've just got round to calculating the NI from equations that have been given to me by the tax office. The problem is my result is always 5p less than it should be. Can anybody see why??

    curPercent = 10
    curUEL = 27820
    curEmpThreshold = 3952

    Code:
    Dim rsNI As ADODB.Recordset
    Dim curGrossPay As Currency
    Dim curEmpThreshold As Currency
    Dim curUEL As Currency
    Dim curPercent As Currency
    Dim curCalc1 As Currency
    Dim curCalc2 As Currency
    Dim curResult As Currency
    
      ' Get NI Data from DB
      Set rsNI = New ADODB.Recordset
      rsNI.CursorType = adOpenForwardOnly
      rsNI.Open "National_Insurance", conCrowd, , , adCmdTable
    
      If not rsNI.EOF Then
      
        curGrossPay = CCur(txtGross.Text)
        curEmpThreshold = CCur(rsNI!NEL_Annual)
        curUEL = CCur(rsNI!UEL_Annual)
        curPercent = CCur(rsNI!Employee_Rate)
      
      End If
    
      rsNI.Close
      Set rsNI = Nothing
    
      ' Calculate Employee Contribution
      curCalc1 = curEmpThreshold / 52
    
      ' As pay period is 1, round down to whole pounds
      curCalc1 = Fix(curCalc1)
    
      curCalc1 = curGrossPay - curCalc1
    
      If curCalc1 <= 0 Then
    
        ' No NI Contribution
        Exit Sub
    
      End If
         
      curCalc2 = curUEL / 52
      
      ' Round up to whole pounds
        
      curCalc2 = Format(curCalc2, "######.##")
      
      If InStr(CStr(curCalc2), ".") <> 0 Then
      
        ' Not a whole pound, Round up
        curCalc2 = Fix(curCalc2)
        curCalc2 = curCalc2 + 1
      
      End If
      
      curCalc2 = curGrossPay - curCalc2
    
      ' If negative treat as zero
      If curCalc2 < 0 Then curCalc2 = 0
    
      curResult = ((curCalc1 - curCalc2) / 100) * curPercent
    Sample results :

    Gross : 280 Result : 20.45 I Get : 20.40
    Gross : 310 Result : 23.45 I Get : 23.40
    Gross : 325 Result : 24.95 I Get : 24.90
    Gross : 400 Result : 32.45 I Get : 32.40

    Any help will be greeted with open arms!!!

  2. #2
    New Member
    Join Date
    Mar 2000
    Posts
    14
    make sure your calculation are done with more than 2 decimals places, and don't round up or down until the very end.

    hope this helps

    FireBeast

  3. #3

    Thread Starter
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    Cheers for the input, but there are rules to when (in the calculation) you are supposed to round. Thanks anyway.

    Anyway I have just found out what was wrong. Nothing!
    The bleeding NI tables are incorrect and have always been out by about 5p every year. Someone could have let me know that before I started checking all my results against them!!


Posting Permissions

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



Click Here to Expand Forum to Full Width