vue.js - Decimal Formatting in Vue Framework
问题描述
I am new to Vue Framework. My requirement is to add money currency formatting in an input box.
Formatting:
I need to add a decimal with two zeros on focus out and remove zero at focus in. The v-modal value should not change as this format is just for the user display.
I found this solution which is quite close to my requirement: https://jsfiddle.net/mani04/w6oo9b6j. There are just two additional things I am not able to implement.
I want to use it like:
<my-currency-input id="test1" name="test2" v-model="price" v-validate="required|numeric” ></my-currency-input>
- I have added vee-validate.js lib for validation for my whole form. So how can I use v-validate in this example?
- I don't want to round off my string. We just need to add and remove (.00) Here, if user enters 35.7896 it is making it 35.79. For my requirement, it should remain 35.7896 as it is already having decimal. It should only add decimal when user enter a number.
How can I do this? Should I use Vue directive for this?
https://jsfiddle.net/mani04/w6oo9b6j/
Something like this I want
<my-currency-input id="test1" name="test2" v-model="price" v-validate="required|numeric” ></my-currency-input>
解决方案
我认为你可以使用{{ parseFloat.($variable).toFixed(2) }}
, is simple 对于 vue.js 的十进制数。你可以试试这个。
推荐阅读
- elasticsearch - 如何结合“AND”和“OR”查询以获得两者的结果?
- python - 如何从异步方法/线程传递/交换数据?
- ios - 当 BLOC 中的流值发生变化时导航到新屏幕
- python - Keras 中的条件批量标准化
- java - 如何创建一个方法来创建由抽象类指定的泛型类的新实例?
- ios - 为什么使用排序键作为 filterExpression 时 AWSDynamoDBScanExpression 返回空?
- python - 多个虚拟机的 Google PubSub 订阅名称?
- excel - 如何使用从用户表单中提取的信息解析一行
- unit-testing - 如何对在 switch 语句中创建多个对象的方法进行单元测试?如何嘲笑他们?
- xamarin - 如何在 xamarin 表单中大写输入和选择器?