jonathanpmartins / v-money3

Vue3 currency input/directive mask
MIT License
103 stars 27 forks source link

Paste not working correctly #93

Open BernardoSM opened 8 months ago

BernardoSM commented 8 months ago

If you set decimals to 2 and paste 1000 value, will be converted to 10.00 and not 1000.00.

How can I fix this? I'd like to paste 1000 and show 1000.00

I'm using the component below:

<input
  v-model.lazy="modelValue"
  v-money3="config"
/>
jonathanpmartins commented 8 months ago

This is the expected behavior with arbitrary precision. You need to pass a string like this: "1000.00". I think what you need is to use the number modifier. From the docs:


Arbitrary Precision

In this release, some breaking changes have been introduced. Let's delve into the details:

v-money3 supports arbitrary precision through the use of BigInt. Arbitrary precision is only supported with v-model. When using v-model, ensure the input is provided as a string representation of a number (e.g., '12345.67'). If your precision is set to 2 and you provide a default v-model value of '55', it will be interpreted as '0.55'. To maintain the correct format, ensure you pass '55.00' when using v-model.

For most users, it's advisable to utilize floating-point numbers and adhere to the boundaries of Number. In such cases, employing v-model with the number modifier, or v-model.number, is recommended. However, this limits you to numbers smaller than 2^53 - 1 or 9007199254740991 (approximately nine quadrillion). Refer to MAX_SAFE_INTEGER for more information. For users employing v-model.number, integers and floats are intuitively understood. If your precision is set to 2 and you input a default v-model.number value of 55, it will be interpreted as 55.00. The same applies to 5.5, which will be rendered as 5.50.

More Examples


You are using the directive applied to a native html component. Will something like this help you?

<input 
    :model-modifiers="{ number: true }" 
    v-model.lazy="amount" 
    v-money3="config"
/>
BernardoSM commented 8 months ago

Hey @jonathanpmartins thanks for the answer.

Unfortunately what I need is changing the "expected" behavior. For me doesn't make sense to paste 1000 (that is an integer) and display 10.00.

In my head if I paste 1000 should display 1000.00 If I paste 10 or 10.00, should display 10.00

Thanks again for the clarification!

jonathanpmartins commented 6 months ago

In my head if I paste 1000 should display 1000.00 If I paste 10 or 10.00, should display 10.00

Isn't this the default behavior with the number modifier set to true? Is the default focusOnRight property set to false?