?
Ce document utilise Manuel du site Web PHP chinois Libérer
格式化數(shù)字為貨幣形式 (如 $1,234.56)。當提供的不是貨幣形式時,會使用本地化默認形式。
{{ currency_expression | currency : symbol}}
$filter('currency')(amount, symbol)
參數(shù) | 類型 | 詳述 |
---|---|---|
amount | number | 用于過濾器的輸入。 |
symbol
(可選)
|
string | 用于顯示的貨幣形式或標識。 |
string | 格式化的數(shù)值。 |
<script>
angular.module('currencyExample', [])
.controller('ExampleController', ['$scope', Function($scope) {
$scope.amount = 1234.56;
}]);
</script>
<div ng-controller="ExampleController">
<input Type="number" ng-model="amount"> <br>
default currency symbol ($): <span id="currency-default">{{amount | currency}}</span><br>
custom currency identifier (USD$): <span>{{amount | currency:"USD$"}}</span>
</div>
it('should init with 1234.56', Function() {
expect(element(by.id('currency-default')).getText()).toBe('$1,234.56');
expect(element(by.binding('amount | currency:"USD$"')).getText()).toBe('USD$1,234.56');});
it('should update', Function() {
if (browser.params.browser == 'safari') {
// Safari does not understand the minus key. See
// https://github.com/angular/protractor/issues/481
return;
}
element(by.model('amount')).clear();
element(by.model('amount')).sendKeys('-1234');
expect(element(by.id('currency-default')).getText()).toBe('($1,234.00)');
expect(element(by.binding('amount | currency:"USD$"')).getText()).toBe('(USD$1,234.00)');});