AngularJS货币过滤器用于将数字转换为货币格式。如果未指定货币格式, 则货币过滤器将使用本地货币格式。
语法如下:
{{ currency_expression | currency : symbol : fractionSize}}
参数:它包含上面提到和下面描述的两个参数:
- 符号:它是可选参数。用于指定货币符号。货币符号可以是任何字符或文本。
- 分数:它是可选参数。用于指定小数位数。
范例1:本示例以印度货币格式显示数字。
<!DOCTYPE html>
< html >
< head >
< title >Currency Filter</ title >
< script src =
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js" >
</ script >
</ head >
< body >
< div ng-app = "gfgApp" ng-controller = "currencyCntrl" >
< h3 >
Currency filter with curreency
symbol and fraction size.
</ h3 >
< p >Amount : {{ amount | currency : "Rs" : 2}}</ p >
</ div >
< script >
var app = angular.module('gfgApp', []);
app.controller('currencyCntrl', function($scope) {
$scope.amount = 75;
});
</ script >
</ body >
</ html >
输出如下:
范例2:本示例以fromat货币形式显示数字。
<!DOCTYPE html>
< html >
< head >
< title >Currency Filter</ title >
< script src =
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js" >
</ script >
</ head >
< body >
< div ng-app = "gfgApp" ng-controller = "currencyCntrl" >
< h3 >
Currency filter without curreency
symbol and fraction size.
</ h3 >
< p >Amount : {{ amount | currency}}</ p >
</ div >
< script >
var app = angular.module('gfgApp', []);
app.controller('currencyCntrl', function($scope) {
$scope.amount = 38;
});
</ script >
</ body >
</ html >
输出如下: