Skip to content

Commit

Permalink
number decimal separator instead of currency separator
Browse files Browse the repository at this point in the history
  • Loading branch information
fmntf committed May 31, 2012
1 parent 1f22b43 commit 0266259
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions accounting.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
* alias: accounting.`parse(string)`
*
* Decimal must be included in the regular expression to match floats (defaults to
* accounting.settings.currency.decimal), so if the number uses a non-standard decimal
* accounting.settings.number.decimal), so if the number uses a non-standard decimal
* separator, provide it as the second argument.
*
* Also matches bracketed negatives (eg. "$ (1.99)" => -1.99)
Expand All @@ -190,8 +190,8 @@
// Return the value as-is if it's already a number:
if (typeof value === "number") return value;

// Default decimal point is "." but could be set to eg. "," in opts:
decimal = decimal || this.settings.currency.decimal;
// Default decimal point comes from settings, but could be set to eg. "," in opts:
decimal = decimal || this.settings.number.decimal;

// Build regex to strip out everything except digits, decimal point and minus sign:
var regex = new RegExp("[^0-9-" + decimal + "]", ["g"]),
Expand Down
4 changes: 2 additions & 2 deletions tests/qunit/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ $(document).ready(function() {
equals(accounting.unformat("string"), 0, 'Returns 0 for a string with no numbers');
equals(accounting.unformat({joss:1}), 0, 'Returns 0 for object');

accounting.settings.currency.decimal = ',';
accounting.settings.number.decimal = ',';
equals(accounting.unformat("100,00"), 100, 'Uses decimal separator from settings');
equals(accounting.unformat("¤1.000,00"), 1000, 'Uses decimal separator from settings');
accounting.settings.currency.decimal = '.';
accounting.settings.number.decimal = '.';
});

test("accounting.toFixed()", function() {
Expand Down

0 comments on commit 0266259

Please sign in to comment.