@tagplus/components 1.2.16 → 1.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "email": "bruno@tagplus.com.br"
9
9
  }
10
10
  ],
11
- "version": "1.2.16",
11
+ "version": "1.2.17",
12
12
  "main": "./dist/tp.common.js",
13
13
  "directories": {
14
14
  "lib": "src/lib"
@@ -39,12 +39,14 @@ function formatMoney (input, toString = false, locale = defaults) {
39
39
  if ((inputString.slice(-1).match(/[.,]/))) {
40
40
  inputString = inputString.substring(0, inputString.length - 1)
41
41
  }
42
+
42
43
  const negative = inputString.indexOf('-') >= 0 ? -1 : 1
43
- const precision = locale.number.precision
44
44
 
45
45
  if (toString) {
46
46
  input = completeZeros(inputString, locale)
47
47
  }
48
+
49
+ const precision = locale.number.precision
48
50
  const numbers = onlyNumbers(input, precision)
49
51
  const currency = numbersToCurrency(numbers, precision)
50
52
  if (toString) {
@@ -63,7 +65,9 @@ function formatMoney (input, toString = false, locale = defaults) {
63
65
  function completeZeros (input, locale) {
64
66
  const precision = locale?.number?.precision || defaults.precision
65
67
  const decimal = locale?.number?.decimal || defaults.decimal
66
- const i = input.indexOf(decimal)
68
+ let i = input.lastIndexOf('.')
69
+ const j = input.lastIndexOf(',')
70
+ i = i > j ? i : j
67
71
  const qntDecimais = i ? input.length - i - 1 : 0
68
72
 
69
73
  // correção para decimal quebrado