user6656728
user6656728

Reputation:

use greater than operand in angularjs controller

Data in my controller

$scope.data = [{
                "F": "1,26,000"
            }];

$scope.data2 = [{
                "F": "26,000"
            }];

this is my data in my controller now i want to use if else condition here

if (Number($scope.data[0].F) > Number($scope.data2[0].F))
   {
      console.log('aaa');
   }
else {
      console.log('bbb');
     }

now if data is greater then data2 ('aaa') should print and of it is less then ('bbb') should print

Now as you see data is greater then data2

('aaa') this should be printed on my console but instead of that ('bbb') this is printing in console,

what i need to change in my controller??

Upvotes: 1

Views: 474

Answers (2)

shaxawan mhammad
shaxawan mhammad

Reputation: 1

var f =parseFloat(($scope.data[0].F).replace(/,/g, ''));

var f2 =parseFloat(($scope.data2[0].F).replace(/,/g, ''));

  if ( f>f2){
      console.log('aa');
   }
else {
      console.log('bbb');
     }

Upvotes: -1

Olli
Olli

Reputation: 532

Remove the commas so it's "126000" and "26000"

Can also do

if (parseInt($scope.data[0].F) > parseInt($scope.data2[0].F))
   {
      console.log('aaa');
   }
else {
      console.log('bbb');
     }

parseInt converts the string to a number.

Upvotes: 2

Related Questions