dqfxao2898
dqfxao2898
2019-05-08 15:14

将数字除以月中的日期只返回一位数字

已采纳

I am trying to calculate what pace our sales team in on for the month, but when I divide our numbers so far (17,305) by the day of the month (08), I am getting the wrong number (2.125).

I've tried converting the date from a string to a number, but I everything I read says php should know how to handle the numbers when it's a string or number.

$dateday = date('d');
$numberofdays = date('t');

echo $ztmmoney.' total for month<br>'; 
echo $dateday.' day of the month<br>';
$mavg = $ztmmoney/$dateday;
echo $mavg.' daily average<br>';
echo $numberofdays.' days in month<br>';
$pace = $mavg * $numberofdays;

echo 'on pace for: '.$pace;

I should see 17,305/8 = 2,163.125

but this is my output:

17,305 total for month

08 day of the month

2.125 daily average

31 days in month

on pace for: 65.875

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongshi3605 dongshi3605 2年前

    You can use this to get rid of the wrong calculation

    $ztmmoney = '17,305';
    $ztmmoney = intval(preg_replace('/[^\d.]/', '', $ztmmoney));
    
    点赞 评论 复制链接分享