如何在我的结果中让php返回指定数量的字符?

时间:2016-02-16 17:25:17

标签: php substr

我已经尝试过substr()但是无法使它工作。我只需要$ leadsmissed,$ panswerrate和$ pcloserate来舍入到最近的整数并显示它。我还需要$ prevenue来显示小数点后的两位数:xxx.xx

我错过了它的语法吗?我对这一切都很陌生。任何帮助,将不胜感激。谢谢!

<?php
$branches  = $_POST['branches'];
$closerate  = $_POST['closerate'];
$ticketsize  = $_POST['ticketsize'];
$leadsperhour = .87;


$revenue = ($branches * $leadsperhour) * $closerate * $ticketsize;
$leadsmissed = $branches * $leadsperhour;

$panswerrate = .92 * $leadsmissed;

$pcloserate = $closerate * $leadsmissed;
$prevenue = $pcloserate * $ticketsize;


$result['string1'] = "Your company, on average, missed " . $leadsmissed . " leads in the   past hour. ";

$result['string2'] =  "With Pronexis, you would have talked to " .     $panswerrate . " of those leads, closed " . $pcloserate . " of them, and received $" . $prevenue . " more revenue!";



echo json_encode($result);
?>

1 个答案:

答案 0 :(得分:0)

舍入到最接近的整数:

$leadsmissed = round($leadsmissed);
$panswerrate = round($panswerrate);
$pcloserate = round($pcloserate);

转换为带有2位小数的浮点数

$prevenue = number_format($prevenue , 2);