qfw
This commit is contained in:
parent
5a0d86e2e9
commit
80c457a21b
@ -140,10 +140,28 @@ const _sfc_main = defineComponent({
|
||||
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;
|
||||
console.log("\u6DFB\u52A0\uFF0C", new String(props.modelValue).replace(reg, "$&,"));
|
||||
currentValue.value = new String(props.modelValue).replace(reg, "$&,");
|
||||
let reg = /\d{1,3}(?=(\d{3})+$)/g;
|
||||
console.log("\u6DFB\u52A0\uFF0C", formatMoney(props.modelValue));
|
||||
currentValue.value = formatMoney(props.modelValue);
|
||||
} catch {
|
||||
currentValue.value = "\u8F93\u5165\u9519\u8BEF";
|
||||
}
|
||||
|
24
lib/index.js
24
lib/index.js
@ -11236,10 +11236,28 @@ const _sfc_main$1v = defineComponent({
|
||||
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;
|
||||
console.log("\u6DFB\u52A0\uFF0C", new String(props.modelValue).replace(reg, "$&,"));
|
||||
currentValue.value = new String(props.modelValue).replace(reg, "$&,");
|
||||
let reg = /\d{1,3}(?=(\d{3})+$)/g;
|
||||
console.log("\u6DFB\u52A0\uFF0C", formatMoney(props.modelValue));
|
||||
currentValue.value = formatMoney(props.modelValue);
|
||||
} catch {
|
||||
currentValue.value = "\u8F93\u5165\u9519\u8BEF";
|
||||
}
|
||||
|
@ -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 = "输入错误"
|
||||
}
|
||||
|
70
umd/index.js
70
umd/index.js
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user