kool_samule Posted November 9, 2009 Share Posted November 9, 2009 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?! Quote Link to comment https://forums.phpfreaks.com/topic/180851-php-rounding-up-issue/ Share on other sites More sharing options...
jonsjava Posted November 9, 2009 Share Posted November 9, 2009 Clear as mud. You are saying that you are getting the proper rounding on everything, but one number shows up as 4.59 when it should be 4.60. How is that number being set? PHP, or MySQL? if it's PHP, have a look at round(), if it's not, we will need more info to help. Quote Link to comment https://forums.phpfreaks.com/topic/180851-php-rounding-up-issue/#findComment-954220 Share on other sites More sharing options...
Mchl Posted November 9, 2009 Share Posted November 9, 2009 If you want a total of rouded numbers you should add rounded numbers not round the sum of unrounded... Quote Link to comment https://forums.phpfreaks.com/topic/180851-php-rounding-up-issue/#findComment-954324 Share on other sites More sharing options...
Daniel0 Posted November 9, 2009 Share Posted November 9, 2009 And to illustrate the difference quite clearly: 1.1 + 1.1 + 1.1 + 1.1 + 1.1 = 5.5 ≈ 6 1.1 ≈ 1 1 + 1 + 1 + 1 + 1 = 5 Quote Link to comment https://forums.phpfreaks.com/topic/180851-php-rounding-up-issue/#findComment-954332 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.