如何在php中乘以两个数字
1) 我从db中检索扣减数据为如何在php中乘以两个数字,php,Php,1) 我从db中检索扣减数据为1000.00,其类型为双精度(10,2) 2) 我已经根据工作日计算了月薪,如下所示, 我把$emppp作为2898.00退出 3) 现在我试着从工资中减去扣除额(1000.00,是从db中减去的),然后它会显示这样的错误 遇到非数字值 “$emppp-$total_did;echo”Rs $amounts=四舍五入($employee\u salary/$days); $amounts=$amounts; $emp_salary=number_格式($total
1000.00
,其类型为双精度(10,2)
2) 我已经根据工作日计算了月薪,如下所示,
我把$emppp
作为2898.00
退出
3) 现在我试着从工资中减去扣除额(1000.00,是从db中减去的),然后它会显示这样的错误
遇到非数字值
“$emppp-$total_did;echo”Rs
$amounts=四舍五入($employee\u salary/$days);
$amounts=$amounts;
$emp_salary=number_格式($totaldays*$amounts,2);
$emppp=str_替换(“,”,“,$emp_工资);
您需要的是:
1.通过执行$totaldays*$amounts
获得$emp\u工资
。(不要在那里使用number\u format()
)
2.现在从$emp\u工资中减去扣除金额
,然后使用数字格式()
示例代码:
<?php
$employee_salary = 45000.00; //assumed
$days = 29; //feb month total days
$totaldays = 20; //days user is present in office
$deduction = 10000.00; // you gave it in your question
$amounts = round($employee_salary/$days);//get per day salary
$emp_salary= $totaldays*$amounts; // get total salary based on days user is present in office
echo $emppp= number_format($emp_salary-$deduction ,2); // now remove deduction amount and use number_format()
1*2
“现在我正在尝试减去扣减”-您显示的代码似乎不包含任何实际的减法运算。始终将货币值存储为整数,并在输出时除以100以获得浮点值。这避免了许多舍入问题。
<?php
$employee_salary = 45000.00; //assumed
$days = 29; //feb month total days
$totaldays = 20; //days user is present in office
$deduction = 10000.00; // you gave it in your question
$amounts = round($employee_salary/$days);//get per day salary
$emp_salary= $totaldays*$amounts; // get total salary based on days user is present in office
echo $emppp= number_format($emp_salary-$deduction ,2); // now remove deduction amount and use number_format()