I have a decimal value of length 15,4 in my database.
I have a number -23.425 I am trying to round down to -23.42
I have tried the following ways but they all seem to round up to -23.43:
sprintf("%.2f", $discountQueryResult['value'])
floor($discountQueryResult['value']*100)/100
Is there any other way to drop the 3rd decimal place?
You're trying to round a negative number. Rounding down a negative number with floor() will increase its absolute value; remember, -23.43(0) is less than -23.425!
Instead, you're looking to round up its value with ceil():
echo ceil(-23.425 * 100) / 100; // -23.42
This can be seen working here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With