Trying to convert this "0.274509817"
to a nice precentage like 27%
The string is a dynamic value from an API.
PHP program to Calculate Percentage php // defining function function cal_percentage($num_amount, $num_total) { $count1 = $num_amount / $num_total; $count2 = $count1 * 100; $count = number_format($count2, 0); return $count; } // calling function to calculate percentage echo "Percentage of 39 in 100 : ".
Example #1 round() examples php echo round(3.4); // 3 echo round(3.5); // 4 echo round(3.6); // 4 echo round(3.6, 0); // 4 echo round(1.95583, 2); // 1.96 echo round(1241757, -3); // 1242000 echo round(5.045, 2); // 5.05 echo round(5.055, 2); // 5.06 ?>
How do you check if number is decimal or not PHP? The is_numeric() function checks whether a variable is a number or a numeric string. This function returns true (1) if the variable is a number or a numeric string, otherwise it returns false/nothing.
$percent = round((float)$str * 100 ) . '%';
Where $str
= "0.274509817"
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