How to convert float percent number value to integer percent number value in PHP?
Example: 3.8461538461538 % = 4 %
Update: Here is my code , I coded to get percent value, but I get decimal value, but I need it without decimal value.
$total = array_sum($total_count);
$percent = ($occurs/$total)*100;
echo $percent ;
echo "%";
<?php number_format(3.8461538461538); ?>
You can specify in second argument the number of decimal points (default is 0).
use round()
. it's a PHP function.
Edit: Given Code:
$total = array_sum($total_count);
$percent = ($occurs/$total)*100;
echo round($percent). "%";
For eg:
$number="3.8461538461538%"; //if it's a string with % in the end.
$number=substr($number, 0,-1); //It type converts automatically here. Lazy code :)
$number_rounded=round($number);
or
$number=3.8461538461538; //If it's just a float.
$number_rounded=round($number);