【发布时间】:2018-10-27 20:41:25
【问题描述】:
目前我正在尝试实现一个基于此示例的 Vue.js 组件:https://jsfiddle.net/mani04/bgzhw68m/。
这是我的源代码的样子:
computed: {
displayValue: {
get: function get() {
if (this.isInputActive) {
return this.price.toString();
} else {
return "€ " + this.price.toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,");
}
},
set: function set(modifiedValue) {
var newValue = parseFloat(modifiedValue.replace(/[^\d\.]/g, ""));
if (isNaN(newValue)) {
newValue = 0;
}
this.price = newValue;
}
}
}
这适用于1.00、1,300,500.25 等值。
现在我想用德语写这些花车:
在德国,我们将1.000.000,50 写成one million and 50 cent。所以你看:, 和 . 被替换了。
那么如何更改我的脚本以使其使用此表示法?真的很重要,我仍然可以使用float。
【问题讨论】:
-
如果您想要一个强大的解决方案来解析不同语言环境中的数字,请考虑使用numeral
标签: javascript jquery vue.js