dqfxao2898 2019-05-08 15:14
浏览 79
已采纳

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

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 2019-05-08 15:17
    关注

    You can use this to get rid of the wrong calculation

    $ztmmoney = '17,305';
    $ztmmoney = intval(preg_replace('/[^\d.]/', '', $ztmmoney));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测