优化商品的条码的自增逻辑,解决长条码的问题
This commit is contained in:
@@ -564,6 +564,36 @@ export function getPrevMonthFormatDate(monthNum) {
|
||||
return prevMonth.getFullYear() + seperator1 + month + seperator1 + strDate
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义大数加法函数,两个数字相加
|
||||
* @param a
|
||||
* @param b
|
||||
* @returns {string}
|
||||
*/
|
||||
export function addBigNumbers(a, b) {
|
||||
a = a.toString();
|
||||
b = b.toString();
|
||||
// 反转字符串,从个位开始计算
|
||||
let aRev = a.split('').reverse();
|
||||
let bRev = b.split('').reverse();
|
||||
const maxLength = Math.max(aRev.length, bRev.length);
|
||||
let result = [];
|
||||
let carry = 0;
|
||||
for (let i = 0; i < maxLength; i++) {
|
||||
const digitA = i < aRev.length ? parseInt(aRev[i]) : 0;
|
||||
const digitB = i < bRev.length ? parseInt(bRev[i]) : 0;
|
||||
const sum = digitA + digitB + carry;
|
||||
result.push(sum % 10);
|
||||
carry = Math.floor(sum / 10);
|
||||
}
|
||||
// 处理最后的进位
|
||||
if (carry > 0) {
|
||||
result.push(carry);
|
||||
}
|
||||
// 反转回来得到正确的结果
|
||||
return result.reverse().join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* JS中根据指定值删除数组中的元素
|
||||
* @param arrylist
|
||||
|
||||
Reference in New Issue
Block a user