Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    IPT calculation (calculate a percentage of a figure)

    Hi,

    I am fairly new to this so please bare with me.

    I have a php page that uses Javascript (I think) to calculate the percentage Insurance Premium Tax (IPT field) of a total.

    I have located where the calculation occurs and can see that it take the total of a predefined amount and divides it by 21 to give me the 5% IPT tax. IPT has risen in the UK today to 6% so I need to know what I need to change the 21 to to give me an accurate IPT calculation.

    Here's a snippet of the code. Can anyone help please? Is it 17.65?

    PHP Code:
    ////////////////////////////////////////////
    // Motor Bike Calculations
    ////////////////////////////////////////////
    $p 3;
    $q 0;
      while (
    $p 6){
      
    $base_array mysql_fetch_row($result4);
      
    // Motor Bikes
      
    $risk_code 2;
      
    $ap = (+ ($p));

              
    $ipt_rate $ipt_main;

      
    $monthly_total $pricing_row[$ap];
      
    // Calculate IPT
      
    $ipt_percentage $monthly_total 21;
      
    $monthly_ipt $ipt_percentage;

        
    $base_cost $base_array[0] + $dealer_loading;
      
    $base_final $base_cost;
      
      
    $profit $monthly_total $base_cost $monthly_ipt;
      
            
    $monthly_total number_format($monthly_total2'.''');
                
    $monthly_ipt number_format($monthly_ipt2'.''');
                    
    $base_final number_format($base_final2'.''');
                        
    $profit number_format($profit2'.''');
                        
      echo 
    '
      <tr align="center" bgcolor="#FFDDFF"> 
        <td>'
    ;
    if (
    $p == 3)
    {
    echo (
    '');
    }
    elseif (
    $p == 4)
    {
    echo (
    'UK');
    }
    elseif (
    $p == 5)
    {
    echo (
    'UK & European');
    }
    echo 
    '</td>
        <td>
            <input name="'
    ;
    if (
    $p == 3)
    {
    echo (
    'comprehensive_plus_'.$risk_code);
    }
    elseif (
    $p == 4)
    {
    echo (
    'comprehensive_'.$risk_code);
    }
    elseif (
    $p == 5)
    {
    echo (
    'driveline_plus_'.$risk_code);
    }


    echo 
    '" type="text" value="'.$pricing_row[$ap].'" size="6" maxlength="6" class="smallinfo">
         </td>
        <td>'
    .$monthly_ipt.'</td>
        <td>'
    .$base_final.'</td>
        <td>'
    .$profit.'</td>
      </tr>'
    ;
      
    $q++;
    $p++;

    Last edited by mynton; 01-04-2011 at 11:05 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    Nope. Not a lick of JavaScript in there. That's 100% PHP code.

    But you know, the language in use has nothing to do with this. It's just simple arithmetic.

    105 / 21 is indeed 5. Simply because, of course, 105 / 5 is 21.


    What you need is to solve for x where 106 / x = 6. And simple algebra says x = 106 / 6 or 17.666666667 (that is 17 and 2/3).

    So, you almost had the right answer. Just a shade off. You might want to multiply by 6 and then divide by 106 to get as accurate an answer as possible.
    Last edited by Old Pedant; 01-04-2011 at 10:20 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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