为什么AngularJS货币筛选器用括号格式化负数?

前端之家收集整理的这篇文章主要介绍了为什么AngularJS货币筛选器用括号格式化负数?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Live Demo

为什么这个:

  1. # Controller
  2. $scope.price = -10;
  3.  
  4. # View
  5. {{ price | currency }}

结果在($ 10.00)而不是 – $ 10.00?

这是代表负货币的流行方式。 Wikipedia

In bookkeeping,amounts owed are often represented by red numbers,or a number in parentheses,as an alternative notation to represent negative numbers.

你可以在Angular源代码中看到他们这样做(negSuf / negPre):

  1. function $LocaleProvider(){
  2. this.$get = function() {
  3. return {
  4. id: 'en-us',NUMBER_FORMATS: {
  5. DECIMAL_SEP: '.',GROUP_SEP: ',',PATTERNS: [
  6. { // Decimal Pattern
  7. minInt: 1,minFrac: 0,maxFrac: 3,posPre: '',posSuf: '',negPre: '-',negSuf: '',gSize: 3,lgSize: 3
  8. },{ //Currency Pattern
  9. minInt: 1,minFrac: 2,maxFrac: 2,posPre: '\u00A4',negPre: '(\u00A4',negSuf: ')',lgSize: 3
  10. }
  11. ],CURRENCY_SYM: '$'
  12. },

猜你在找的Angularjs相关文章