What is currency filter in AngularJS ?
Last Updated :
12 Apr, 2022
In this article, we will know the currency filters in AngularJS, along with understanding its implementation through the examples. Filters are used to modify or format the given data in a certain way. AngularJS has different filters such as uppercase, lowercase, etc. One of those filters is the currency filter.
The Currency filter modifies or formats a given number into a currency. In other terms, we are just taking a number and displaying it in a specific currency format.
Syntax for HTML Template:
{{ amount | currency : symbol : fractionSize}}
Syntax for JavaScript:
$filter('currency')(amount, symbol, fractionSize)
Parameters: It accepts 2 parameters, which are described below:
- amount: The number input needed to format into currency.
- symbol: It is an optional parameter where we provide the symbol or identifier we want to display. By default, it is set to the dollar symbol.
- fractionSize: It round of the specific number to particular decimal places. It's an optional parameter & by default, it is set to the default max for the current locale.
Example: This example describes the currency filter without using the optional parameters.
HTML
<html>
<head>
<title>Currency Filter</title>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js">
</script>
</head>
<body>
<center>
<h1>GeeksforGeeks</h1>
<h3>
Currency Filter without optional parameters
</h3>
<div ng-app="myApp"
ng-controller="currencyCtrl">
<p>Number: {{curr}}</p>
<p>After applying currency filter: </p>
<p>Price = {{ curr | currency}}</p>
</div>
<script>
var app = angular.module('myApp', []);
var curr = 1000.5555;
app.controller('currencyCtrl', function($scope) {
$scope.curr = curr;
});
</script>
</center>
</body>
</html>
Output:
Currency filter without parameters
Example: This example describes the currency filter with optional parameters.
HTML
<html>
<head>
<title>Currency Filter</title>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js">
</script>
</head>
<body>
<center>
<h1>GeeksforGeeks</h1>
<h3>Currency Filter with optional parameters</h3>
<div ng-app="myApp"
ng-controller="currencyCtrl">
<p>Number: {{curr}}</p>
<p>After applying currency filter: </p>
<p>Price = {{ curr | currency : "₹" :3}}</p>
</div>
<script>
var app = angular.module('myApp', []);
var curr = 1000.5555;
app.controller('currencyCtrl', function($scope) {
$scope.curr = curr;
});
</script>
</center>
</body>
</html>
Output:
Currency filter with parameters
Similar Reads
What is CurrencyPipe in Angular 10 ? In this article, we are going to see what is CurrencyPipe in Angular 10 and how to use it. CurrencyPipe is used to transform a number to a currency string, formatted according to locale rules that determine group sizing and separator, decimal-point character Syntax: {{ value | currency }} Approach:
1 min read
AngularJS currency Filter AngularJS currency filter is used to convert a number into a currency format. If no currency format is specified currency filter uses the local currency format. Syntax: {{ currency_expression | currency : symbol : fractionSize}}Parameters: It contains 2 parameters as mentioned above and described be
2 min read
What are expressions in AngularJS ? In this article, we will see the expressions in Angular JS, along with knowing the different methods for implementing it through the code examples.Expressions in AngularJS, are the statements that are to be evaluated, that is placed inside the double curly braces. The result of the evaluation will b
5 min read
What is pipe() function in Angular ? Angular stands out as a liked JavaScript framework for developing web applications. In Angular, the pipe() function plays a vital role in transforming data within templates. It allows you to apply various transformations to data before displaying it in the view. In this article, we will explore more
4 min read
AngularJS limitTo Filter The limitTo filter in AngularJS is used to return an array or a string that contains a specified number of elements. This filter can be used with arrays, strings, and numbers. The basic principle, however, remains the same in all three cases: For arrays, it returns an array containing only the speci
2 min read