Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中乘以两个数字_Php - Fatal编程技术网

如何在php中乘以两个数字

如何在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

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_格式($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()