add AIAgent

This commit is contained in:
Timi
2026-09-16 01:39:44 +08:00
parent c29436f845
commit a6f9fabcec
11 changed files with 1266 additions and 5 deletions
+15
View File
@@ -85,6 +85,21 @@ export function convertPackageQuantity(quantity: number | string, fromBaseQuanti
return formatDecimal(numerator / denominator, 3, 3);
}
/** 将基础单位数量换算为业务单位展示数量,结果最多保留三位小数。 */
export function convertBaseQuantityToPackageQuantity(baseQuantity: number | string, baseQuantityPerUnit: number | string): string | undefined {
const quantityParts = toDecimalParts(baseQuantity, 3);
const unitParts = toDecimalParts(baseQuantityPerUnit, 6);
if (!quantityParts || !unitParts || unitParts.value === 0n) {
return undefined;
}
const numerator = quantityParts.value * 10n ** BigInt(unitParts.scale + 3);
const denominator = 10n ** BigInt(quantityParts.scale) * unitParts.value;
const quotient = numerator / denominator;
const remainder = numerator % denominator;
const rounded = denominator < remainder * 2n ? quotient + 1n : quotient;
return formatDecimal(rounded, 3, 3);
}
/** 精确相加两个最多三位小数的数量。 */
export function addPackageQuantity(left: number | string, right: number | string): string | undefined {
const leftParts = toQuantityParts(left);