@tagplus/components 1.2.2 → 1.2.3

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.2",
11
+ "version": "1.2.3",
12
12
  "main": "./dist/tp.common.js",
13
13
  "directories": {
14
14
  "lib": "src/lib"
@@ -22,10 +22,20 @@ export const toCurrency = (val) => {
22
22
  if (val === '') {
23
23
  return val
24
24
  }
25
- return (parseInt(val * 100) / 100).toLocaleString(t('locale.prefix'), {
26
- minimumFractionDigits: 2,
27
- maximumFractionDigits: 2
28
- })
25
+
26
+ try {
27
+ let with2Decimals = val.toString().match(/^-?\d+(?:\.\d{0,2})?/)[0]
28
+ with2Decimals = Number(with2Decimals.toLocaleString(t('locale.prefix'), {
29
+ minimumFractionDigits: 2,
30
+ maximumFractionDigits: 2
31
+ }))
32
+ return with2Decimals
33
+ } catch (Exception) {
34
+ return val.toLocaleString(t('locale.prefix'), {
35
+ minimumFractionDigits: 2,
36
+ maximumFractionDigits: 2
37
+ })
38
+ }
29
39
  }
30
40
 
31
41
  /**