Rajesh Gami

Rajesh Gami

  • 79
  • 24.4k
  • 1.3m

Display only 2 decimal point : AngularJS 1.0

May 16 2018 11:22 PM
How to display only 2 decimal point in output of angularJS.
 
Supppose my percentage is 81.6777776777 % but i want to display it 81.67 % .
 
 My code of angularJS:
 
 
 
 Controller.js
  1. app.controller("AngularJs_ImageController"function ($scope, $timeout, $rootScope, $window, $http, myService) {  
  2.   
  3. $scope.finalSubmit = function () {  
  4.         $http({  
  5.             method: 'POST',  
  6.             url: '/Exam/FinalSubmit/'  
  7.             //params: { ESTQUserAnswer: setUserAns, ESTQId: ESTQId, ESTQIsMark: ESTQIsMark }  
  8.           });  
  9.   
  10.             $scope.txtAnswer = "";  
  11.             var percentage = ($scope.totalPoints * 100) / $scope.textbox; // E.X (3 * 100) / 7  = 42.85714285714286  
  12.             $scope.Resuts1 = "You gotted " + percentage + " %";  
  13.             if (percentage >= 70) {  
  14.                 $scope.Resuts = "You are Pass " + $scope.Resuts1;  
  15.                  
  16.                 swal("Pass""You are Pass " + $scope.Resuts1, "success")  
  17.                 $scope.ImageAnswer = "won.png";  
  18.             }  
  19.             else {  
  20.                 $scope.Resuts = "Sorry " + $scope.usrName + " You are Fail " + $scope.Resuts1;  
  21.   
  22.                 swal("Fail""You are fail " + $scope.Resuts1, "error")  
  23.                   
  24.                 $scope.ImageAnswer = "lose.png";  
  25.             }  
  26.   
  27.             $scope.showGameStart = false;  
  28.             $scope.showGame = false;  
  29.             $scope.showresult = true;  
  30.             return;  
  31.             return;          
  32.     }  
  33.   
  34. )}; 
 in view Result.cshtml
  1. <div ng-show="showresult">  
  2.       <p>   {{Resuts}}  </p>  
  3. </div> 
 
 Output is:
 
   Sorry Rajesh You are Fail, You gotted 42.85714285714286 %
 
But i want to display this to: 42.85 % , How is possible in angularJS.
 
Thanx in advance
 
 

Answers (1)