AngularJs Round to 2 decimal places


AngularJs Round to 2 decimal places: We often need to round decimal numbers upto two places. We can use JavaScript toFixed() method to round the decimal number upto to the two places. Here in this tutorial we are going to explain how you can use this method to round the decimal numbers. You can also use our online editor to edit and run the code online.


AngularJs Round to 2 decimal places Example

You can use JavaScript toFixed() method to round the decimal numbers upto two places simply as below-

AngularJs Round to 2 decimal places Example:

<!DOCTYPE html>
<html lang="en">
<head>
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
 <script>
var myApp = angular.module("myApp", []);
 myApp.controller("myController", function($scope) {
 $scope.testNumber = 99.3213;
 $scope.result = '';
 $scope.roundNumberExample = function(){
  $scope.result = $scope.testNumber.toFixed(2);
 }
});
</script>
</head>
<body>  
<div ng-app="myApp">  
<div ng-controller="myController"> 
<button type="button" ng-click="roundNumberExample()">Click Me</button>
<p>Result = {{result}}</p>
</div> 
</div>
</body>  
</html>  

Try it »

If you run the above example it will produce the output something like this –

AngularJs Round to 2 decimal places

Advertisements

Add Comment