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

Precision not working properly #62

Closed
kevinlester opened this issue Dec 19, 2023 · 2 comments
Closed

Precision not working properly #62

kevinlester opened this issue Dec 19, 2023 · 2 comments

Comments

@kevinlester
Copy link

Love the component, but I discovered an issue with precision that is quite baffling. In short, the precision attribute that is set in one instance of the component is somehow impacting the precision in another instance of the component when the model is updated. Consider the following code. In it, I have two vue-number components that show the correct data when rendered. When the button is pressed and the model is updated, the re-rendered values do NOT show the expected values. More info below:

<template>
  <vue-number v-model="current_record['price1']" v-bind="options" :minimum-fraction-digits=4 :precision=4 /> {{current_record['price1']}}<br/>
  <vue-number v-model="current_record['price2']" v-bind="options" :minimum-fraction-digits=1 :precision=1 /> {{current_record['price2']}}<br/>
  <button @click="() => {current_record = {'price1': 34.567, 'price2': 34.567}}">Change</button><br/>
</template>

<script setup>
import {ref} from "vue";
import { component as VueNumber } from '@coders-tm/vue-number-format'

const options = ref({
  decimal: '.',
  separator: ',',
  prefix: '',
  masked: false
})

const current_record = ref( {'price1': 12.345, 'price2': 12.345})

</script>

On first render, the values correctly show:
input1: 12.3450
input2: 12.3

When the button is pressed, the values are then incorrectly set to:
input1: 34.6000
input2: 34.6

The expected values are:
input1: 34.5670
input2: 34.6

From trial and error, it appears as though the precision setting being used during re-rendering is always the last one set on the page. My page has lots of vue-number components, and when I update the model to which they are attached, all precision values are set to the value on the last vue-number component. Curiously, the minimum-fraction-digits work fine, it just appears to be the precision attribute that is not behaving.

This is quite baffling to me and I didn't think that it was possible, but I am able to see it consistently in my app. Any assistance would be appreciated.

@dipaksarkar
Copy link
Contributor

Please try latest version

@kevinlester
Copy link
Author

Latest version addresses the issue. Thank you!

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

2 participants