从十进制开始的百分比?菲律宾比索

php
2022-08-30 21:47:16

试图将其转换为一个不错的precentage,例如"0.274509817"27%

该字符串是来自 API 的动态值。


答案 1
$percent = round((float)$str * 100 ) . '%';

哪里$str = "0.274509817"


答案 2
$number = 0.274509817;
echo round( $number * 100 ), '%';

推荐