Jump to content

Round() issue .... should be straightforward i hope


Accurax

Recommended Posts

Hi guys,

 

I hope this is a simple question.... i just cant find the answer atm.

 

I have a set of cash vluse calculated from a base price and a percentage discount.

 

Now, when this comes out at lets say 12.995 I would like to round this to 12.99 and not 13 as im currently getting .... is there any way of doing this?

 

Really appreciate any help you can give :)

Assuming you always want to round down the fraction of the penny then multiply by 100, round down, divide by 100:

 

$var = 12.995;
$var = floor($var*100)/100;
echo $var;

 

zenag, that will round to 13. A half rounds up.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.