SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Rounding Up Issue

    Hi Chaps,

    I have an SQL query that calculates a word count multiplied by a fixed figure:

    Code:
    ...$pricegross = ($row_rsInvPending['projanalysis_total']*$row_rsInvPending['costbase']);...
    Then use a bit of php code to round up the figure to 2 decimal places....

    HTML Code:
    <?php echo number_format($pricegross, 2, '.', ''); ?>
    I then total up $pricegross for all records:

    Code:
    .....SELECT SUM(projanalysis_total) as total_pricegross...
    If I have two records:
    ($pricegross) 1. 2.295
    ($pricegross) 2. 2.295
    There are both displayed as 2.30, which is what I want

    Then the total ($total_pricegross) shows up as 4.59, but what I want is: 4.60

    Is this possible?....Hope this is clear?!

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Since you do the multiplying and the rounding up in PHP, just do the summing up of the results of those operations in PHP as well.

  3. #3
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but how do I do that?

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Post your code, and I might be able to tell you where you have to add some lines

  5. #5
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    rsInvPending:
    Code:
    mysql_select_db($database_conndb2, $conndb2);
    $query_rsInvPending = "SELECT jobid, jobno, jobdruck, jobname, jobtype, jobmodel, tbl_projects.projid, tbl_projects.projtitle, tbl_projects.projdue, tbl_projects.projtype, DATE_FORMAT(tbl_projects.projdue, '%d/%m/%Y') as projdue_format, (tbl_projects.projanalysis_b_rep+tbl_projects.projanalysis_b_100+tbl_projects.projanalysis_b_95_99+tbl_projects.projanalysis_b_85_94+tbl_projects.projanalysis_b_75_84+tbl_projects.projanalysis_b_50_74+tbl_projects.projanalysis_b_nm) as projanalysis_total, (tbl_projects.projanalysis_b_rep+tbl_projects.projanalysis_b_75_84+tbl_projects.projanalysis_b_50_74+tbl_projects.projanalysis_b_nm) as projanalysis_full, (tbl_projects.projanalysis_b_95_99+tbl_projects.projanalysis_b_85_94) as projanalysis_fuzzy, tbl_projects.projanalysis_b_100 as projanalysis_proof, tbl_costs.costbase, tbl_costs.costnm_84, tbl_costs.cost85_99, tbl_costs.cost100, tbl_costs.costrep FROM tbl_jobxml, tbl_projects, tbl_costs WHERE jobinvtype = 'UAESD' AND jobnextinv='y' AND jobinvsent='n' AND tbl_projects.projid=tbl_jobxml.FK_projid";
    $rsInvPending = mysql_query($query_rsInvPending, $conndb2) or die(mysql_error());
    $row_rsInvPending = mysql_fetch_assoc($rsInvPending);
    $totalRows_rsInvPending = mysql_num_rows($rsInvPending);
    rsTotals:
    Code:
    mysql_select_db($database_conndb2, $conndb2);
    $query_rsTotals = "SELECT SUM(projanalysis_total) as words_gross, SUM(projanalysis_full) as words_full, SUM(projanalysis_fuzzy) as words_fuzzy, SUM(projanalysis_proof) as words_proof FROM (  SELECT jobid, FK_projid, jobno, jobdruck, jobname, jobtype, jobmodel, jobinvtype, jobnextinv, jobinvsent, tbl_projects.projid, tbl_projects.projtitle, tbl_projects.projdue, tbl_projects.projtype, DATE_FORMAT(tbl_projects.projdue, '%d/%m/%Y') as projdue_format, (tbl_projects.projanalysis_b_rep+tbl_projects.projanalysis_b_100+tbl_projects.projanalysis_b_95_99+tbl_projects.projanalysis_b_85_94+tbl_projects.projanalysis_b_75_84+tbl_projects.projanalysis_b_50_74+tbl_projects.projanalysis_b_nm) as projanalysis_total, (tbl_projects.projanalysis_b_rep+tbl_projects.projanalysis_b_75_84+tbl_projects.projanalysis_b_50_74+tbl_projects.projanalysis_b_nm) as projanalysis_full, (tbl_projects.projanalysis_b_95_99+tbl_projects.projanalysis_b_85_94) as projanalysis_fuzzy, tbl_projects.projanalysis_b_100 as projanalysis_proof, tbl_costs.costbase, tbl_costs.costnm_84, tbl_costs.cost85_99, tbl_costs.cost100, tbl_costs.costrep FROM tbl_jobxml, tbl_projects, tbl_costs )SomeAlias WHERE jobinvtype = 'UAESD' AND jobnextinv='y' AND jobinvsent='n' AND projid=FK_projid";
    $rsTotals = mysql_query($query_rsTotals, $conndb2) or die(mysql_error());
    $row_rsTotals = mysql_fetch_assoc($rsTotals);
    $totalRows_rsTotals = mysql_num_rows($rsTotals);
    CALCULATOR
    PHP Code:
    <?php 
    $pricegross 
    = ($row_rsInvPending['projanalysis_total']*$row_rsInvPending['costbase']);
    $pricenet = (($row_rsInvPending['projanalysis_full'])*($row_rsInvPending['costbase'])*($row_rsInvPending['costnm_84']/100))+(($row_rsInvPending['projanalysis_fuzzy'])*($row_rsInvPending['costbase'])*($row_rsInvPending['cost85_99']/100))+(($row_rsInvPending['projanalysis_proof'])*($row_rsInvPending['costbase'])*($row_rsInvPending['cost100']/100));
    $pricediscount $pricegross $pricenet;
    $total_pricegross = ($row_rsTotals['words_gross']*$row_rsInvPending['costbase']);
    $total_pricenet = (($row_rsTotals['words_full'])*($row_rsInvPending['costbase'])*($row_rsInvPending['costnm_84']/100))+(($row_rsTotals['words_fuzzy'])*($row_rsInvPending['costbase'])*($row_rsInvPending['cost85_99']/100))+(($row_rsTotals['words_proof'])*($row_rsInvPending['costbase'])*($row_rsInvPending['cost100']/100));
    $total_pricediscount $total_pricegross $total_pricenet;
    ?>
    TABLE:
    HTML Code:
    <table border="0" cellpadding="0" cellspacing="0" id="tblrepeat">
      <caption><img src="../Images/invoicing.jpg" /></caption>
        <tr class="checkpoint" >
          <th class="checkpoint" colspan="5">Project / Document</th>
          <th class="checkpoint" colspan="4">Analysis</th>
          <th class="checkpoint" colspan="3">Costing / Discount</th>
        </tr>
        <tr>
          <th height="21">Project No.</th>
          <th>Project Title</th>
          <th>Druck-NR</th>
          <th>Type</th>
          <th>Deadline</th>
          <th>Total</th>
          <th>Full</th>
          <th>Fuzzy</th>
          <th>Proof</th>
          <th>Full Price</th>
          <th>Discount Price</th>
          <th>Total</th>
          </tr>
        <?php do { ?>
            <tr>
            <td><?php echo $row_rsInvPending['projid']; ?></td>
            <td><?php echo $row_rsInvPending['projtitle']; ?></td>
            <td><?php echo $row_rsInvPending['jobdruck']; ?></td>
            <td><?php echo $row_rsInvPending['projtype']; ?></td>
            <td><?php echo $row_rsInvPending['projdue_format']; ?></td>
            <td><?php echo $row_rsInvPending['projanalysis_total']; ?></td>
            <td><?php echo $row_rsInvPending['projanalysis_full']; ?></td>
            <td><?php echo $row_rsInvPending['projanalysis_fuzzy']; ?></td>
            <td><?php echo $row_rsInvPending['projanalysis_proof']; ?></td>
            <td> <?php echo number_format($pricegross, 2, '.', ''); ?></td>
            <td> <?php echo number_format($pricediscount, 2, '.', ''); ?></td>
            <td> <?php echo number_format($pricenet, 2, '.', ''); ?></td>
          </tr>
          <?php } while ($row_rsInvPending = mysql_fetch_assoc($rsInvPending)); ?>
          <tr>
            <td colspan="12">&nbsp;</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td><div align="right"><span class="blueBold">Totals:</span></div></td>
            <td><span class="blueBold"><?php echo $row_rsTotals['words_gross']; ?></span></td>
            <td><span class="blueBold"><?php echo $row_rsTotals['words_full']; ?></span></td>
            <td><span class="blueBold"><?php echo $row_rsTotals['words_fuzzy']; ?></span></td>
            <td><span class="blueBold"><?php echo $row_rsTotals['words_proof']; ?></span></td>
            <td><span class="blueBold"> --TOTAL PRICE (GROSS)--</span></td>
            <td><span class="blueBold"> --TOTAL PRICE (DISCOUNT)--</span></td>
            <td><span class="blueBold"> --TOTAL PRICE (NET)--</span></td>
          </tr>
      </table>


Bookmarks

Posting Permissions

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