Reputation: 526
I am calculating a number which I use in another calculation. the problem is this number could be 67.9699 I want it to say 67.96 without rounding up or down just chop the other digits of. I was hoping the floor function would do this like:
$num2 = floor(($num1/5)*100)/100;
How ever this is still rounding the number up to 67.97 is there a away to stop this. Any help welcome
Upvotes: 1
Views: 1530
Reputation: 310
It's working well for me, try this:
echo floor(67.9699 * 100) / 100;
By the way, number_format()
rounds the number.
Upvotes: 3
Reputation: 416
$num2 = substr($num2,0,5);
echo $num2;
If you want to use the number again as float
$num2 = floatval($num2);
Upvotes: 0