@tagplus/components 4.3.1 → 4.4.1
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/dist/tp.common.js +1 -1
- package/dist/tp.common.js.map +1 -1
- package/dist/tp.umd.js +1 -1
- package/dist/tp.umd.js.map +1 -1
- package/dist/tp.umd.min.js +1 -1
- package/dist/tp.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/currency.js +7 -4
package/package.json
CHANGED
package/src/utils/currency.js
CHANGED
|
@@ -38,7 +38,6 @@ function unformat (input, precision = defaults.precision) {
|
|
|
38
38
|
* @returns
|
|
39
39
|
*/
|
|
40
40
|
function formatMoney (input, toString = false, locale = defaults, customPrecision = false) {
|
|
41
|
-
console.log(' customPrecision-> ', customPrecision)
|
|
42
41
|
let inputString = (`${input}`)
|
|
43
42
|
|
|
44
43
|
// Impede de digitar . ou , porque o formatador já adiciona
|
|
@@ -53,7 +52,6 @@ function formatMoney (input, toString = false, locale = defaults, customPrecisio
|
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
const precision = customPrecision || locale.number.precision
|
|
56
|
-
console.log(' precision-> ', precision)
|
|
57
55
|
|
|
58
56
|
const numbers = onlyNumbers(input, precision)
|
|
59
57
|
const currency = numbersToCurrency(numbers, precision)
|
|
@@ -92,7 +90,12 @@ function completeZeros (input, locale) {
|
|
|
92
90
|
return input
|
|
93
91
|
}
|
|
94
92
|
|
|
95
|
-
function onlyNumbers (input) {
|
|
93
|
+
function onlyNumbers (input, precision = defaults.precision) {
|
|
94
|
+
const numbersAfterComma = input.split(',')[1]?.length || 0
|
|
95
|
+
// if the numbers after the comma are less than the precision, add zeros
|
|
96
|
+
if (numbersAfterComma < precision) {
|
|
97
|
+
input += '0'.repeat(precision - numbersAfterComma)
|
|
98
|
+
}
|
|
96
99
|
return toStr(input).replace(/\D+/g, '') || '0'
|
|
97
100
|
}
|
|
98
101
|
|
|
@@ -108,7 +111,7 @@ function between (min, n, max) {
|
|
|
108
111
|
function numbersToCurrency (numbers, precision) {
|
|
109
112
|
const exp = Math.pow(10, precision)
|
|
110
113
|
const float = parseFloat(numbers) / exp
|
|
111
|
-
|
|
114
|
+
console.log('numbersToCurrency -> ', float.toFixed(fixed(precision)))
|
|
112
115
|
return float.toFixed(fixed(precision))
|
|
113
116
|
}
|
|
114
117
|
|