mirror of
https://github.com/HackPlan/accounting.js.git
synced 2026-01-12 17:02:24 +08:00
number decimal separator instead of currency separator
This commit is contained in:
@@ -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)
|
||||
@@ -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"]),
|
||||
|
||||
@@ -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("<22>1.000,00"), 1000, 'Uses decimal separator from settings');
|
||||
accounting.settings.currency.decimal = '.';
|
||||
accounting.settings.number.decimal = '.';
|
||||
});
|
||||
|
||||
test("accounting.toFixed()", function() {
|
||||
|
||||
Reference in New Issue
Block a user