Reputation: 2403
Trying to convert this "0.274509817"
to a nice precentage like 27%
The string is a dynamic value from an API.
Upvotes: 20
Views: 38649
Reputation: 20016
and after that, append
"%"
to get the percent sign (e.g. if used with sprintf).
Upvotes: 0
Reputation: 74202
$number = 0.274509817;
echo round( $number * 100 ), '%';
Upvotes: 2
Reputation: 17390
$percent = round((float)$str * 100 ) . '%';
Where $str
= "0.274509817"
Upvotes: 48