Results 1 to 2 of 2

Thread: Comparisons

  1. #1
    Join Date
    Dec 1969

    Default Comparisons

    I am trying to work out tax owed where there are 4 bands. The lower and upper limits are stored in a database (along with the relevant years) and all the results seem to be entirely wrong. <BR><BR>And example is: <BR>up to £4,615 tax free <BR>between £4,616 - £6,535 10% <BR>between £6,536 - £34,515 22% <BR>over £34,516 + 40% <BR><BR>so I need to work out which bracket gross salary falls in.<BR><BR>I have the following defined: <BR><BR>a = (request.Form("gross"))<BR>b = (request.Form("paid"))<BR>c = (RS("startlow")) <BR>d = (RS("starthigh"))<BR>e = (RS("basiclow"))<BR>f = (RS("basichigh"))<BR>g = (RS("higherlow"))<BR><BR>I have also done<BR><BR>a = FormatCurrency(a)<BR>b = FormatCurrency(b) <BR>... etc etc so that they are all the same format <BR><BR>I have done a resonse.write to debug and the output from these variables are: <BR><BR>c = £4,616.00 <BR>d = £6,535.00 <BR>e = £6,536.00 <BR>f = £34,515.00 <BR>g = £34,516.00 <BR><BR>Now in order to work out the brackets I have done: <BR><BR>1. Is the gross salary less than the threshold where you start paying tax? <BR><BR>(a &#060; c) returns FALSE with a = 500, FALSE for 5,000, TRUE for 20,000 and FALSE for 50,000<BR><BR>2. Does the gross salary fall into the 10% tax bracket?<BR><BR>((c &#060; a) AND (a &#060; d)) returns TRUE with a = 500, TRUE for 5,000, FALSE for 20,000 and TRUE for 50,000<BR><BR>3. Does the gross salary fall into the 22% tax bracket?<BR><BR>((e &#060; a) AND (a &#060; f)) returns FALSE for any of those values of a<BR><BR>4. Is the gross salary above the threshold for paying 40% tax?<BR><BR>(g &#060; a) returns TRUE with a = 500, TRUE for 5,000, FALSE for 20,000 and TRUE for 50,000<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default You blew it big time... using Format Currency!<BR><BR>The very *LAST* thing you wanted to do before you started making comparisons and playing with the numbers was to CONVERT THEM INTO STRINGS!<BR><BR>And that&#039;s *exactly* what FormatCurrency does! Converts a number into a string. <BR><BR>You ONLY use FormatCurrency (or any of the FormatXXX functions) when you are FINALLY ready to write the data to the screen. You chould never work with the numbers in string format or try to send info created using FormatXXX to a database!<BR><BR>As soon as you converted those numbers to strings, *NOW* you are doing STRING comparisons!<BR><BR>THINK ABOUT IT! <BR><BR>Is "£AAAA" greater or less than "£B" ???<BR><BR>Hopefully, you know that "B" is greater than "A", so even though the "£AAAA" is *longer*, the STRING "£B" is greater.<BR><BR>SAME WHEN YOU DO "£4,616" vs. "£2222222222". The "4" is greater than the "2", because they are being compared *as strings*.<BR><BR>So now get rid of the silly FormatCurrency stuff and try again.<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