Link to home
Start Free TrialLog in
Avatar of deanlee17
deanlee17

asked on

Round calculation to the nearest pound

Hi guys,

I have the following calc, how can I round it to the nearest pound? £2.50 would be £3.00 and £2.49 would be £2.00 etc...

<?php $TheVar = $rows_product[$i]['product_rrp'] - $rows_product[$i]['product_price']; ?>

Thanks,
Dean
ASKER CERTIFIED SOLUTION
Avatar of EmuL8_sw
EmuL8_sw
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chris Stanyon
If your variables contain the pound sign, then you'll need to strip that out. Also, if you need the output to include the decimals, you've got number_format().

$rrp = str_replace('£', '', $rows_product[$i]['product_rrp']);
$price = str_replace('£', '', $rows_product[$i]['product_rrp']);

$TheVar = round($rrp - $price);

echo number_format($TheVar,2);

Open in new window

hi.. please use this

float round ( float $val [, int $precision = 0 [, int $mode = PHP_ROUND_HALF_UP ]] )

or

<?php
echo(round(0.60) . "<br>");
echo(round(0.50) . "<br>");
echo(round(0.49) . "<br>");
echo(round(-4.40) . "<br>");
echo(round(-4.60));
?>