Skip to main content
November 9, 2009
Answered

PHP Rounding Up Issue

  • November 9, 2009
  • 1 reply
  • 330 views

Hi Chaps,

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

"...$pricegross = ($row_rsInvPending['projanalysis_total']*$row_rsInvPending['costbase']);..."

Then use a bit of php code to round up the figure to 2 decimal places....

<?php echo number_format($pricegross, 2, '.', ''); ?>

I then total up $pricegross for all records:

".....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?!

This topic has been closed for replies.
Correct answer bregent

I don't know php, but wouldn't you just use the same rounding function (assuming that's what number_format is doing)?

<?php echo number_format($total_pricegross, 2, '.', ''); ?>

1 reply

bregentCorrect answer
Participating Frequently
November 9, 2009

I don't know php, but wouldn't you just use the same rounding function (assuming that's what number_format is doing)?

<?php echo number_format($total_pricegross, 2, '.', ''); ?>