©
Dieses Dokument verwendetPHP-Handbuch für chinesische WebsitesFreigeben
格式化数字为货币形式 (如 $1,234.56)。当提供的不是货币形式时,会使用本地化默认形式。
{{currency_expression|currency:symbol}}
$filter('currency')(amount,symbol)
参数 | 类型 | 详述 |
---|---|---|
amount | number | 用于过滤器的输入。 |
symbol
(可选)
|
string | 用于显示的货币形式或标识。 |
string | 格式化的数值。 |
angular.module('currencyExample',[]).controller('ExampleController',['$scope',Function($scope){$scope.amount=1234.56;}]);ng-controller="ExampleController">Type="number"ng-model="amount">
default currency symbol ($):id="currency-default">{{amount | currency}}
custom currency identifier (USD$):{{amount | currency:"USD$"}}
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/481return;}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)');});