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>

2 Answers 2

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;
}
Sign up to request clarification or add additional context in comments.

3 Comments

is parseFloat() angularjs function?
No, it is native JavaScript.
That is a good point. You will have to put the parseFloat() in your controller. See this post stackoverflow.com/questions/12755558/….
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.