Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Approximate count in PHP

Tags:

php

mysql

I have a website that contains a list of articles. I want to include a line that says how many articles there are in the DB, however I don't want it to show the exact count.

I would like it to round down to the nearest 10, so for example for 105 articles I would like it to say "100+", etc.

How would I go about doing this?

like image 613
Sherwin Flight Avatar asked Aug 20 '26 13:08

Sherwin Flight


2 Answers

Quite simple:

floor($num / 10) * 10

docs

like image 188
Shad Avatar answered Aug 23 '26 02:08

Shad


To do something similar you have to use the logarithm with base = 10 and round it

$exp= floor(log($num)/log(10));
$num = pow(10,$exp)."+";

This works with 10, 100, 1000 ecc, i think it better do what you asked.

like image 28
kappa Avatar answered Aug 23 '26 04:08

kappa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!