I'm having trouble maintaining the decimal format when trying to input currency values using numeraljs and plain javascript. I can't seem to find a solution to this issue. Below is my code snippet:
<input v-model="amountValue"></input>`
<script>
import import numeral from 'numeral';
data: function() {
return {
formData:{
amount: "",
},
};
},
computed:{
amountValue: {
get(){
return this.formData.amount
},
set(value){
this.formData.amount = numeral(value).format('0,0[.]00')
console.log(this.formData.amount)
}
}
},
// I have also tried without numeraljs
computed:{
amountValue: {
get(){
return this.formData.amount
},
set(value){
this.formData.amount = parseInt(value).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
console.log(this.formData.amount)
}
}
},
The input field successfully displays the thousand separator, but struggles to retain the decimal point.
While typing, the value includes the thousand separator, however, when attempting to input a decimal point, it gets removed.