为什么AngularJS货币过滤器格式负数用括号? [英] Why AngularJS currency filter formats negative numbers with parenthesis?

查看:1295
本文介绍了为什么AngularJS货币过滤器格式负数用括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现场演示

为什么这样的:

# Controller
$scope.price = -10;

# View
{{ price | currency }}

结果($ 10.00),而不是 - $ 10.00

推荐答案

这是重新present负货币的一种流行方式。 维基百科

This is a popular way to represent negative currencies. Wikipedia:

在记账,欠款往往是通过重新红色数字psented $ P $,或在括号内的数字,作为替代的符号来重新present负数。

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

您可以在角源$ C ​​$ C,他们这样做( negSuf / 议价pre

You can see in the Angular source code where they do this (negSuf/negPre):

function $LocaleProvider(){
  this.$get = function() {
    return {
      id: 'en-us',

      NUMBER_FORMATS: {
        DECIMAL_SEP: '.',
        GROUP_SEP: ',',
        PATTERNS: [
          { // Decimal Pattern
            minInt: 1,
            minFrac: 0,
            maxFrac: 3,
            posPre: '',
            posSuf: '',
            negPre: '-',
            negSuf: '',
            gSize: 3,
            lgSize: 3
          },{ //Currency Pattern
            minInt: 1,
            minFrac: 2,
            maxFrac: 2,
            posPre: '\u00A4',
            posSuf: '',
            negPre: '(\u00A4',
            negSuf: ')',
            gSize: 3,
            lgSize: 3
          }
        ],
        CURRENCY_SYM: '$'
      },

这篇关于为什么AngularJS货币过滤器格式负数用括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆