AngularJS number filter is used to convert a number into a string or text. We can also define a limit to display a number of decimal digits. The number filter rounds off the number to specified decimal digits.
Syntax:
{{ string| number : fractionSize}}
Parameter Values: It contains single parameter value fractionsize which is of type number and used to specify the number of decimals.
Example 1: This example format the number and set it into the fraction with two decimal places.
HTML
<!DOCTYPE html>
< html >
< head >
< title >Number Filter</ title >
< script src =
</ script >
</ head >
< body >
< div ng-app = "gfgApp" ng-controller = "numberCntrl" >
< h1 style = "color: green" >GeeksforGeeks</ h1 >
< h3 >Number filter with fraction size.</ h3 >
< p >Number : {{ value| number : 2}}</ p >
</ div >
< script >
var app = angular.module('gfgApp', []);
app.controller('numberCntrl', function($scope) {
$scope.value = 75598.548;
});
</ script >
</ body >
</ html >
|
Output:
Example 2: This example format the number and set it into the fraction with three decimal places.
HTML
<!DOCTYPE html>
< html >
< head >
< title >Number Filter</ title >
< script src =
</ script >
</ head >
< body >
< div ng-app = "gfgApp" ng-controller = "numberCntrl" >
< h1 style = "color: green" >GeeksforGeeks</ h1 >
< h3 >Number filter without fraction size.</ h3 >
< p >Number : {{ value| number}}</ p >
</ div >
< script >
var app = angular.module('gfgApp', []);
app.controller('numberCntrl', function($scope) {
$scope.value = 524598.54812;
});
</ script >
</ body >
</ html >
|
Output:
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
03 Aug, 2022
Like Article
Save Article