十进制的百分比?PHP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5055387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:40:25 来源:igfitidea点击:
Percent from decimal? PHP
提问by AndrewFerrara
Trying to convert this "0.274509817"
to a nice precentage like 27%
试图将其转换"0.274509817"
为一个不错的百分比,例如27%
The string is a dynamic value from an API.
该字符串是来自 API 的动态值。
回答by Alec Gorge
$percent = round((float)$str * 100 ) . '%';
Where $str
= "0.274509817"
其中$str
="0.274509817"
回答by Alan Haggai Alavi
$number = 0.274509817;
echo round( $number * 100 ), '%';
回答by MestreLion
round((float)$value * 100) . '%'
回答by Scott C Wilson
and after that, append
在那之后,追加
"%"
to get the percent sign (e.g. if used with sprintf).
获取百分号(例如,如果与 sprintf 一起使用)。
回答by chx
What's the problem with intval($a * 100) . '%'
?
有什么问题intval($a * 100) . '%'
?