1

I have 3 column in a table deduction,advance , total. first two columns have their value from database and 3rd column is sum of 1st two column but instead of summation i am getting result as concatenated.

<td data-title="'deduction>'">
   <span >{{payroll.deduction}}</span>
</td>
<td data-title="'advance''">
   <span >{{payroll.advance}}</span>
</td>
<td data-title="'total">
   <span >{{payroll.deduction+payroll.deduction}}</span>
</td>
Nisham Mahsin
  • 1,399
  • 5
  • 19
  • 43

2 Answers2

2

Your variables are being treated as strings. Try using parseFloat() to convert them to numbers:

<td data-title="'deduction>'">
   <span >{{ payroll.deduction }}</span>
</td>
<td data-title="'advance''">
   <span >{{ payroll.advance }}</span>
</td>
<td data-title="'total">
   <span >{{ parseFloat(payroll.deduction) + parseFloat(payroll.advance) }}</span>
</td>

Edit:

AngularJS expressions are not the exactly the same as JavaScript expressions. You will have to add a paseFloat to your controller in order to pull in the native parseFloat function:

function controller($scope)
{
    $scope.parseFloat = parseFloat;
}
Bradley Trager
  • 3,570
  • 3
  • 26
  • 33
0

Instead of parseFloat use parseInt function. One more thing i would like you to suggest to check in console whether its getting you string or not.

Nitin Agarwal
  • 943
  • 1
  • 13
  • 26