From 7956b316f13845c1cbe9b5746b4c4938a1c457da Mon Sep 17 00:00:00 2001 From: Paulette Luftig Date: Thu, 12 Oct 2017 12:21:25 -0700 Subject: [PATCH 1/3] unformat with the decimal specified to deal with decimal for thousands Signed-off-by: Brad Midgley --- accounting.js | 2 +- tests/qunit/methods.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/accounting.js b/accounting.js index fd181fd..1ee6033 100644 --- a/accounting.js +++ b/accounting.js @@ -284,7 +284,7 @@ } // Clean up number: - number = unformat(number); + number = unformat(number, decimal); // Build options object from second param (if object) or all params, extending defaults: var opts = defaults( diff --git a/tests/qunit/methods.js b/tests/qunit/methods.js index 19e354b..79198b7 100644 --- a/tests/qunit/methods.js +++ b/tests/qunit/methods.js @@ -7,6 +7,7 @@ $(document).ready(function() { equals(accounting.unformat(1234567890), 1234567890, 'Returns same value when passed an integer'); equals(accounting.unformat("string"), 0, 'Returns 0 for a string with no numbers'); equals(accounting.unformat({joss:1}), 0, 'Returns 0 for object'); + equals(accounting.unformat("30.612", "."), 30.612); accounting.settings.number.decimal = ','; equals(accounting.unformat("100,00"), 100, 'Uses decimal separator from settings'); @@ -48,6 +49,7 @@ $(document).ready(function() { equals(accounting.formatMoney(-500000, "£ ", 0), "£ -500,000", 'negative values, custom params, works ok'); equals(accounting.formatMoney(5318008, { symbol: "GBP", format: "%v %s" }), "5,318,008.00 GBP", "`format` parameter is observed in string output"); equals(accounting.formatMoney(1000, { format: "test %v 123 %s test" }), "test 1,000.00 123 $ test", "`format` parameter is observed in string output, despite being rather strange"); + equals(accounting.formatMoney('30.671', "R$ ", 0, ".", ","), "R$ 30.671", "`decimal` acts as thousands in formatting"); // Format param is an object: var format = { From 4dc5f64ff4e9c7e9a7b1b079b393a09a8b32335b Mon Sep 17 00:00:00 2001 From: Paulette Luftig Date: Mon, 23 Oct 2017 13:57:17 -0700 Subject: [PATCH 2/3] only pass in decimal to unformat when parsing Brazilian Real --- accounting.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/accounting.js b/accounting.js index 1ee6033..8b246c6 100644 --- a/accounting.js +++ b/accounting.js @@ -284,7 +284,11 @@ } // Clean up number: - number = unformat(number, decimal); + if (symbol == "B$") { + number = unformat(number, decimal); + } else { + number = unformat(number); + } // Build options object from second param (if object) or all params, extending defaults: var opts = defaults( From fd5ab6b12927897f629f2d31d197c7e31162d189 Mon Sep 17 00:00:00 2001 From: Paulette Luftig Date: Mon, 23 Oct 2017 14:38:36 -0700 Subject: [PATCH 3/3] fix symbol typo --- accounting.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounting.js b/accounting.js index 8b246c6..5a0c914 100644 --- a/accounting.js +++ b/accounting.js @@ -284,7 +284,7 @@ } // Clean up number: - if (symbol == "B$") { + if (symbol == "R$") { number = unformat(number, decimal); } else { number = unformat(number);