Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong behavior when formating string values #64

Open
AlexanderYW opened this issue Apr 14, 2018 · 3 comments
Open

Wrong behavior when formating string values #64

AlexanderYW opened this issue Apr 14, 2018 · 3 comments

Comments

@AlexanderYW
Copy link

Expected Behavior

If you input a String with "20000.00" as value the output value will be 20.000,00

Actual Behavior

Right now when you input a String with "20000.00" as value the output value will be 2.000.000,00

Steps to Reproduce the Problem

https://codepen.io/anon/pen/vRqyay

Specifications

  • Plugin Version: v2.3.0
  • Vue.js Version: v2.5.16
  • Browser: Chrome, Edge
  • OS: Windows 10
@lulessa
Copy link

lulessa commented May 5, 2018

+1 to this issue. It happens in the valueNumber computed property in mounted via process method

valueNumber () {
return this.unformat(this.value)

When unformat receives "12345.00", it tells accounting to convert string to number assuming the decimal separator is ,, but it isn't.

return accounting.unformat(toUnformat, this.decimalSeparatorSymbol)

Workaround, as seen on codepen, is to make the initial value a Number, then pass into the component via v-model.

A possible long-term solution in the component is to make valueNumber detect if this.value is a numeric string (!this.value.toString.test(/^[\d\.]/)) and then convert it to Numeric before passing it to unformat. However, that would not work correctly if value was "1.001" (one thousand and one) with . as thousand separator.

@WulfP
Copy link

WulfP commented Jul 4, 2018

Here ist my (short-term) solution:

add

value = parseFloat(value.replace ? value.replace(",",".") : value)

as first line to

methods.unformat() #363

Numeric values from input-fields can now contain comma as decimal-separator and are converted properly if stored as strings

@scramatte
Copy link

Same issue here

Please fix it into the component package
Might be interesting to let set array of allowed chars for thousand and decimals separator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants