Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to show round figure number in php?

I have a variable called $totalResults which has dynamic values, depend on database entries. I need to show a limit like if $totalResults has 154 results then I want show that 154 out of 500. But I want it dynamically, like if the result cross 500, example the result value is 514, then it’ll show like 514 out of 1000.

I don’t want to use if, else conditions because the result will gradually increase, so i need to compare it dynamically, Like if result has 1500 entries, then I’ll add +500 into it, Then it’ll show Like 1500 out of 2000.

I am confused in this part, If the result is not round figure, how can I make it right?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My Logic:

$totalResult = 154;
$newResult = $totalResult + 500;

//Result = 654
But I want to show this 154 out of 500 or 154 out of 1000

>Solution :

You can use the ceil function

$totalResult =154;
$coparisonQuotient = ceil($totalresults/500);
$outOf = $comparisonQuotient * 500;

echo $totalResult. " out of " .$outOf;

Now, if the total results is 154, it would display 154 out of 500

If it is above 500, but less than 1000, let’s say 784. It will display 784 out of 1000

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading