【发布时间】:2012-04-29 08:54:06
【问题描述】:
我想用 PHP 计算一个数字的百分比。例如:
$percentage = 50;
$totalWidth = 350;
对于本例,350 的 50% = 175
我该怎么做?
【问题讨论】:
标签: php percentage
我想用 PHP 计算一个数字的百分比。例如:
$percentage = 50;
$totalWidth = 350;
对于本例,350 的 50% = 175
我该怎么做?
【问题讨论】:
标签: php percentage
$percentage = 50;
$totalWidth = 350;
$new_width = ($percentage / 100) * $totalWidth;
【讨论】:
($totalWidth*$percentage)/100 是一样的,但我更喜欢它。
将$percentage 除以100 并乘以$totalWidth。简单的数学。
【讨论】: