简体   繁体   中英

How to populate JSON data without losing floating precision

I have a JSON file. While populating that file into table using ng-repeat , i'm not getting the zero after decimal point.

For example, i have the points 6.0 . It is displaying only 6 but not zero. Why this happening? How to solve this? That zero is very important for me as i used that for filtering the data.Kindly someone suggest me how to solve this issue.

<tr ng-repeat="x in filtered=(Results | filter: strSearch)">
  <td>#{{$index + 1}}</td>
  <td>{{ x.Name }}</td>
  <td>{{x.DeadLines.Fall}}</td>
  <td>{{x.GRE}}</td>
  <td>{{x.IELTS}}</td>
</tr>

This is the code which i have written. In Ielts , 6.0 is displaying as 6. But i want to display as 6.0 itself. But when i use 6.01 or 6.1 its displaying.

$scope.Results = [{
      "Address": "https://grad.ucla.edu/gasaa/deptinfo/deptinfointro.asp",
      "ApplicationFee": 110,
      "DeadlineLink": "https://grad.ucla.edu/gasaa/deptinfo/deptinfointro.asp",
      "GPA": 3.0,
      "GRE": 320,
      "GRE_ETSCode": 4837,
      "IELTS": 6.0;

This is my sample JSON file.

You can use {{variableName | number:precision}} {{variableName | number:precision}} .

Also not sure, but while parsing variable, 6.00 will be considered as integer and not float, hence it is represented as 6 and not 6.00

JSFiddle .

 function myCtrl($scope){ $scope.number = []; $scope.number.push(6.00); for(var i=0; i<5; i++){ $scope.number.push(Math.random()); } } 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script> <div ng-app> <div ng-controller="myCtrl"> <h3>No formatting</h3> <ul ng-repeat="n in number"> <li>{{n}}</li> </ul> <h3>Formatting </h3> <ul ng-repeat="n in number"> <li>{{n|number:2}}</li> </ul> </div> </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM