qfw
This commit is contained in:
@@ -114,11 +114,31 @@ const onBlur = (event: Event) => {
|
||||
onNumberBlur(event);
|
||||
}
|
||||
if(props.qfw){
|
||||
var formatMoney=function(s){
|
||||
var noNegative = true;
|
||||
s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(2) + "";
|
||||
if(parseFloat(s) < 0){
|
||||
s = Math.abs(s).toFixed(2) + "";
|
||||
noNegative = false;
|
||||
}
|
||||
|
||||
var l = s.split(".")[0].split("").reverse(),
|
||||
r = s.split(".")[1];
|
||||
var t = "";
|
||||
for(let i = 0; i < l.length; i++) {
|
||||
if(i%3==2&&i!=l.length-1){
|
||||
t+=l[i]+",";
|
||||
}else{
|
||||
t+=l[i]+""; //加上空格
|
||||
}
|
||||
}
|
||||
return (noNegative?"":"-") + t.split("").reverse().join("") + "." + r;
|
||||
}
|
||||
try{
|
||||
let reg = /\B(?=(\d{3})+$)/g;
|
||||
let reg = /\d{1,3}(?=(\d{3})+$)/g;
|
||||
// new String(props.modelValue).replace(reg, '$&,');
|
||||
console.log("添加,", new String(props.modelValue).replace(reg, '$&,'))
|
||||
currentValue.value = new String(props.modelValue).replace(reg, '$&,');
|
||||
console.log("添加,", formatMoney(props.modelValue))
|
||||
currentValue.value = formatMoney(props.modelValue);
|
||||
}catch{
|
||||
currentValue.value = "输入错误"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user