Browse Source

[FIX] rounding computation

Gogs 7 years ago
parent
commit
24a3e1f363
2 changed files with 7 additions and 7 deletions
  1. 7 4
      src/components/filters/currency.js
  2. 0 3
      src/components/steps/PaymentAmount.vue

+ 7 - 4
src/components/filters/currency.js

@@ -1,9 +1,11 @@
 /**
  * 
  */
-const currency = (value = '0', symbol = '$', symbolPosition = 'before', thousandsSeparator = '.', decimalPlaces = 2, decimalSeparator = ',', decimalZeros = false) => {
-    if (!(value instanceof String)) {
-        value = value.toString()
+const currency = (value = 0, symbol = '$', symbolPosition = 'before', thousandsSeparator = '.', decimalPlaces = 2, decimalSeparator = ',', decimalZeros = false) => {
+    value = value.toString()
+
+    if (decimalPlaces > 2) {
+        decimalPlaces = 2
     }
 
     value = value.split('.')
@@ -11,7 +13,8 @@ const currency = (value = '0', symbol = '$', symbolPosition = 'before', thousand
     value[0] = value[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, `$1${thousandsSeparator}`)
 
     if (!!value[1]) {
-        value[1] = Number.parseFloat(`0.${value[1]}`).toFixed(decimalPlaces).replace(/0./g, '')
+        value[1] = Number.parseFloat(`0.${value[1]}e${decimalPlaces}`)
+        value[1] = Math.round(value[1])
     }
 
     value = value.join(decimalSeparator)

+ 0 - 3
src/components/steps/PaymentAmount.vue

@@ -82,9 +82,6 @@
             return {
                 paymentResidual: 0
             }
-        },
-        mounted() {
-            console.log()
         }
     }
 </script>