Home » Php » How to Multiply two numbers in php

How to Multiply two numbers in php

Posted by: admin February 25, 2020 Leave a comment

Questions:

1)I am retrieving the deduction data from db as 1000.00 and its type is in double(10,2)

2) And i have calculated monthly salary based on working days as shown below,
i am getting out put of $emppp as 2898.00;

3) Now i am trying to subtract deduction(1000.00 which is from db)from salary then its showing the error like this

A non-numeric value encountered

<th class='text-right'>".$emppp-$total_did;echo"Rs</th>

$amounts=round($employee_salary/$days);
$amountss=$amounts;
$emp_salary=number_format($totaldays*$amountss,2);
$emppp=str_replace(',','',$emp_salary);
How to&Answers:

What you need is like this:

1.get $emp_salary by doing $totaldays*$amounts. (don’t use number_format() there)

2.Now subtract deduction amount from $emp_salary and then use number_format()

Sample code:

<?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()

Output: https://3v4l.org/O8PO1

More reduced code: https://3v4l.org/oftfC