Files
WorthPath/apps/web/src/repayment.ts
T
陈煜 b2c22ca050 feat: add repayment discounts and interactive net worth trends
Support positive repayment discounts and negative surcharges with exact decimal conversion. Add independent trend toggles, pointer and keyboard date inspection, tests and Chinese documentation.
2026-10-04 22:25:32 +08:00

8 lines
435 B
TypeScript

// UI: positive discount, negative surcharge. API stores the opposite fee sign.
// Flip the decimal string directly to preserve all eight fractional digits.
export function repaymentFee(discount: string) {
if (!/^-?(0|[1-9]\d{0,15})(\.\d{1,8})?$/.test(discount)) throw new Error('还款优惠格式无效');
if (/^-?0(?:\.0+)?$/.test(discount)) return '0';
return discount.startsWith('-') ? discount.slice(1) : '-' + discount;
}