Question

I Need to format a number for a Mysqli query.

it can be [1] [1.1] [1.111111..] and has to be the format [1.10] later.

i tried to use number_format($number, 2, ',', ' '); wich actually works.

But the Problem is, this rounds up. eg. for 1.555555555, it does 1.56 as result. is there a way to just format it to 2 decimals without rounding? like just delete everything afert the 2nd decimal?

Was it helpful?

Solution

Do you mean the following?

<?php
 $number = 1.956;
 $number_floored = floor($number*100)/100;
 echo $number_floored; //1.95
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top