我正试图完善以下数据:
Case 1:
round( ((4/6) * 100), 2 ) . '%'; = 66.67%
round( ((1/6) * 100), 2 ) . '%'; = 16.67%
round( ((1/6) * 100), 2 ) . '%'; = 16.67%
Total % = 66.67 + 16.67 + 16.67 = 100.01%
Case 2:
round( ((5/11) * 100), 2 ) . '%'; = 45.45%
round( ((3/11) * 100), 2 ) . '%'; = 27.27%
round( ((3/11) * 100), 2 ) . '%'; = 27.27%
Total % = 45.45 + 27.27 + 27.27 = 99.99%
任何人都可以告诉我如何让它完美100%
由于
答案 0 :(得分:1)
如果省长100
为100.00
,请使用此案例:
round( ((4/6) * 100), 3 ); = 66.667
round( ((1/6) * 100), 3 ); = 16.667
round( ((1/6) * 100), 3 ); = 16.667
round(66.667+16.667+16.667, 2); = 100
echo round( ((5/11) * 100), 3 ); = 45.455
echo round( ((3/11) * 100), 3 ); = 27.273
echo round( ((3/11) * 100), 3 ); = 27.273
echo round(45.455+27.273+27.273, 2); = 100
您可以通过提高舍入精度来使其更加完美,例如:使用15代替3代表双倍值;)。
或
$a1 = (4/6)*100;
$b1 = (1/6)*100;
$c1 = (1/6)*100;
round($a1, 2);
round($b1, 2);
round($c1, 2);
round($a1+$b1+$c1, 2);
$a2 = (5/11)*100;
$b2 = (3/11)*100;
$c2 = (3/11)*100;
round($a2, 2);
round($b2, 2);
round($c2, 2);
round($a2+$b2+$c2, 2);