0

How to treat 1 and the number of decimals should be zero eg) 1.000 as same show the alert pop up number should be same.And the maximum number length of the texbox is 7.

eg)1 and 1.00000001 be different

And the number be 1 and 1.01 as different.Here I have numeric value 1 and numeric value 1. any decimal number.

if the number is 1 and 1.00 means show alert value same and 1.01, or 1.001 or any decimals after number it will be considered as different.

Here is my sample code:

       <!doctype html>
        <html ng-app>
          <head>
            <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
            <script src="script.js"></script>
          </head>
          <body>
        <div ng-controller="Ctrl">
         <input type="text" ng-model="contractDetailsScreen.percent"  maxlength="7" numbers-only="numbers-only" />  
          <button ng-click="actionme()">click</button>
        </div>
          </body>
        </html>



function Ctrl($scope) {
  $scope.actionme = function(){

    if($scope.contractDetailsScreen.percent){

      alert('value same');
    }
else{
  alert("value diffrent");
}
  };
}

Demo: http://plnkr.co/edit/nxRca6HRQGkVO18c3uXa?p=preview

4

1 回答 1

1

使用 parseFloat 转换数字然后匹配值

控制器代码

$scope.actionme = function(){

    var num = parseFloat ($scope.contractDetailsScreen.percent);
         if(1 == num) {
           $scope. result = "Matched";

         } else {
           $scope.result = "not Matched";
         }
      };

工作演示

于 2017-05-29T10:28:09.700 回答