Most likely you want round instead of floor . But otherwise, this would be the most βstandardβ way to do this. Alternatively, you can use sprintf , for example:
sprintf("%.2f%%", $x * 100) , which will print the percentage value of $ x with two decimal precision points and a percent sign after that.
The shortest way to do this is with NumberFormatter :
$formatter = new NumberFormatter('en_US', NumberFormatter::PERCENT); print $formatter->format(.45);
It would be better to do this if your application supports various locales, but otherwise you just add one more line of code so as not to bring much benefit.
source share