0

Here is the $provided in the angular.js file that forces negative numbers to have the minus sign. I would rather not modify the angular.js source code.

$provide.value("$locale", {
  "DATETIME_FORMATS": {
*
*
*
"NUMBER_FORMATS": {
    "CURRENCY_SYM": "$",
    "DECIMAL_SEP": ".",
    "GROUP_SEP": ",",
    "PATTERNS": [
      {
        "gSize": 3,
        "lgSize": 3,
        "maxFrac": 3,
        "minFrac": 0,
        "minInt": 1,
        "negPre": "-",
        "negSuf": "",
        "posPre": "",
        "posSuf": ""
      },
      {
        "gSize": 3,
        "lgSize": 3,
        "maxFrac": 2,
        "minFrac": 2,
        "minInt": 1,
        "negPre": "-\u00a4",
        "negSuf": "",
        "posPre": "\u00a4",
        "posSuf": ""
      }
    ]
  },
*
*
*

I want to overwrite this behavior and have a custom configuration file that will give negative numbers parenthesis instead of the negative sign.

Current output: -48.25 Desired output: (48.25)

  • Um it would be easier to intercept the result then try and change the underlying behavior because you don't know what changing to to parentheses might break (just for example if there is a math function somewhere in the process parentheses rather then negative numbers will be processed differently in the basic JavaScript math – Binvention Jan 15 '16 at 01:34
  • Wouldn't it work to have a custom $locale configuration file that overwrites this behavior? – Justin Andrews Jan 15 '16 at 01:53
  • It might work yes. I was just making that suggestion because as angular changes and possibly as it currently is it's hard to tell just how much changing one part of the default will cause. Some of the defaults you can change easily others cause problems. I wouldn't say don't try it at all but if you're looking for something that has minimal chance of breaking anything else intercepting the result would be it. – Binvention Jan 15 '16 at 01:55
  • This answer might be relevant http://stackoverflow.com/a/30122327/20489 – bingles Mar 01 '16 at 19:12

2 Answers2

0

What about:

"PATTERNS": [
  {
    "gSize": 3,
    "lgSize": 3,
    "maxFrac": 3,
    "minFrac": 0,
    "minInt": 1,
    "negPre": "(",
    "negSuf": ")",
    "posPre": "",
    "posSuf": ""
  },
  {
    "gSize": 3,
    "lgSize": 3,
    "maxFrac": 2,
    "minFrac": 2,
    "minInt": 1,
    "negPre": "(\u00a4",
    "negSuf": ")",
    "posPre": "\u00a4",
    "posSuf": ""
  }
]
bb94
  • 1,294
  • 1
  • 11
  • 24
  • I have thought about that but I would rather not change the angular.js file. I would rather have a custom locale configuration file that will overwrite this angular.js file. – Justin Andrews Jan 15 '16 at 01:35
  • I was thinking that isn't good practice to change the code in the angular.js file because I would then have to test the code and maintain it myself. Isn't it better to overwrite default angularjs behavior rather than change source code? Also I don't know what all depends on that code and I don't want to break anything. – Justin Andrews Jan 15 '16 at 01:58
  • I actually don't know much about angular.js itself. Sorry. – bb94 Jan 15 '16 at 03:17
0

Try changing negPre and negSuf:

$provide.value("$locale", {
  "DATETIME_FORMATS": {
*
*
*
"NUMBER_FORMATS": {
    "CURRENCY_SYM": "$",
    "DECIMAL_SEP": ".",
    "GROUP_SEP": ",",
    "PATTERNS": [
      {
        "gSize": 3,
        "lgSize": 3,
        "maxFrac": 3,
        "minFrac": 0,
        "minInt": 1,
        "negPre": "(",
        "negSuf": ")",
        "posPre": "",
        "posSuf": ""
      },
      {
        "gSize": 3,
        "lgSize": 3,
        "maxFrac": 2,
        "minFrac": 2,
        "minInt": 1,
        "negPre": "(\u00a4",
        "negSuf": ")",
        "posPre": "\u00a4",
        "posSuf": ""
      }
    ]
  },
*
*
*
asiviero
  • 1,225
  • 10
  • 16
  • I would rather not change the angular.js file. I don't know what all depends on that code and I don't want to break anything. – Justin Andrews Jan 15 '16 at 01:52