I am trying to format currency entered value in input field using numeraljs and plain javascript but it keeps deleting the decimal. Can not figure out how to fix this. My code below
<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)
}
}
},
It works with the thousand separator but the decimal wont stay.
When I start typing, it formats the input value(with thousand separator) but when I type in a decimal, it deletes it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…