AngularJs Round to 2 decimal places

AngularJs Round to 2 decimal places

Welcome to the In infinityknow.com website! You will Step By Step learn web programming, easy and very fun. This website allmost provides you with a complete web programming tutorial presented in an easy-to-follow manner. Each web programming tutorial has all the practical examples with web programming script and screenshots available.AngularJs Round to 2 decimal places Example

First of all the Add libs in angularjs.Include script and define a simple controller and one init simple module create.Convert a simple number int into a string, int two decimal keeping only two decimals examples:

Core Logic of the AngularJs Round to 2 Decimal places

var infinityknow = angular.module("infinityknow", []);
 infinityknow.controller("ng4freeCtrl", function($scope) {
 $scope.nwnumber = 199.3213;
 $scope.response = '';
 $scope.myfunction = function(){
  $scope.response = $scope.nwnumber.toFixed(3);
 }
});

Round to at most 2 decimal places Example
Use Math.round(num * 100) / 100

AngularJs math, round to two decimal places

parseFloat("98989.456").toFixed(2);

var testnum = 989898.23454;
numb = testnum.toFixed(2);

<!DOCTYPE html>
<html lang="en">
<head>
<title>AngularJs Round to 2 decimal places Example</title>
 <script src="https://infinityknow.com/libs/angular.min.js"></script>
 <script>
var infinityknow = angular.module("infinityknow", []);
 infinityknow.controller("ng4freeCtrl", function($scope) {
 $scope.nwnumber = 199.3213;
 $scope.response = '';
 $scope.myfunction = function(){
  $scope.response = $scope.nwnumber.toFixed(3);
 }
});
</script>
</head>
<body>  
<div ng-app="infinityknow">  
<div ng-controller="ng4freeCtrl"> 
{{nwnumber}}
<button type="button" ng-click="myfunction()">Click Me</button>
<p>response = {{response}}</p>
</div> 
</div>
</body>  
</html>  

Demo Example

READ :  Angular ng model Directive Example

AngularJs Round to 2 decimal places Example | angularjs toFixed function | angular function

We hope you get an idea about AngularJs Round to 2 decimal places
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.

We hope This Post can help you…….Good Luck!.

Add a Comment

Your email address will not be published. Required fields are marked *