Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何实现百分比计算:
$x=3; $y = 100\$x; // 3.333.. $x*$y - and here I need to get 100 without Observational error
有任何想法吗?
您的反斜杠 ( \) 不是除法符号。您必须使用除法/符号。
\
/
这是一个使用number_format()它将四舍五入到小数点后两位(百分之一位置)的示例。
number_format()
$x = 3; $y = 15; $percent = $x/$y; $percent_friendly = number_format( $percent * 100, 2 ) . '%'; // change 2 to # of decimals