Reputation: 6123
I am working with Angular and I am trying to do this
<td>{{(obj.revenue.total / obj.clicks.total).toFixed(2)}}</td>
and in the table the result is something like this
**EPC**
0.60
NaN // returns this, why ?
I prepared a JSFiddle where you will see this
<table>
<tr>
<th ng-repeat='header in headers'>{{header}}</th>
</tr>
<tr ng-repeat='obj in data'>
<td></td>
<td>{{obj.clicks.total.toFixed(2)}}</td>
<td>{{obj.landing_pages.total_clicks.toFixed(2)}}</td>
<td>{{obj.landing_pages.click_through_rate.toFixed(2)}}</td>
<td>{{obj.conversions.total.toFixed(2)}}</td>
<td>{{(obj.conversions.total / obj.landing_pages.total_clicks)}}</td>
<td>{{obj.conversions.amount.toFixed(2)}}</td>
<td>{{obj.cost.total.toFixed(2)}}</td>
<td>{{(ob.conversions.amount - obj.cost.total).toFixed(2)}}</td>
<td>{{obj.net.roi.toFixed(2)}}</td>
<td>{{obj.cost.cpc}}</td>
<td>{{(obj.revenue.total / obj.clicks.total).toFixed(2)}}</td>
<td>{{obj.cost.ecpc.toFixed(2)}}</td>
</tr>
</table>
and the controller
.controller('PeopleCtrl', function($scope) {
$scope.headers = [
'Traffic Source',
'Clicks',
'LP Clicks',
'LP CTR',
'Conv',
'CVR',
'Rev',
'Spend',
'Profit',
'ROI',
'CPC',
'EPC',
'EPA'
];
$scope.data = [];
$scope.LoadMyJson = function() {
angular.forEach(myJson, function(items) {
$scope.data.push(items)
})
};
$scope.LoadMyJson();
})
see the td
s CVR, Profit and EPC, are the ones where I need to calculate.
Do you guys have an idea of the issue ?
Upvotes: 1
Views: 1766
Reputation: 28750
You can use the fractionSize filter:
<td>{{obj.clicks.total | fractionSize: 2}}</td>
You can see the example here:
https://docs.angularjs.org/api/ng/filter/number
Upvotes: 1