Skip to content

bug(portfolio-import): 数量/成本单元格尾随 % 无法解析为数值 #409

Open
wannT-1/folio
#5

Description

@wannT-1

现象

部分券商/表格导出会把数量或成本写成带百分号的文本(例如误把权重列当成本、或单元格格式带 %)。toFiniteNumber 目前只去掉 ,、$ 与空白,不去掉 %,因此 12.5% → Number('12.5%') → NaN → undefined,行被标成 Invalid quantity/cost。

证据(当前 main)

packages/shared/src/portfolio-import/parsers.ts:

const cleaned = trimmed.replace(/[,$\s]/g, '')
const parsed = Number(cleaned)

复现

Symbol,Quantity,Cost
AAPL.US,10,100%

或 Quantity 为 10%。

  • 实际:对应字段 undefined + Invalid cost price "100%"(或 quantity 同类)。
  • 预期:至少把尾随/多余的 % 剥掉后再解析;若业务上 % 表示「权重而非成本」,则应给出明确 issue,而不是笼统的 Invalid(本 issue 建议先做「剥掉纯装饰 % 得到有限数字」的最小修复,不擅自把权重列映射成成本)。

建议修复(小范围)

  • toFiniteNumber:在现有清理后,若剩余字符串匹配 /^-?\d+(\.\d+)?%$/,剥掉 % 再 Number。
  • 不把 % 解释成「除以 100」(避免把成本 100% 错成 1)。
  • 补回归:100% → 100;12.5% → 12.5;正常无 % 数字不受影响。

范围

与 #358(货币符号前缀)正交:本条是后缀 %,不是 HK$/US$。

查重

未见专门覆盖百分号后缀的 open issue;#356–#360 未包含此项。

Activity

  1. wannT-1 commented on Oct 30, 2026

    @wannT-1
    Author

    /claim

    我来修 toFiniteNumber 对尾随 % 的解析(剥掉装饰 %,不除以 100),并补 focused 回归。提交 PR 时写 Closes #409。

  2. github-actions commented on Oct 30, 2026

    @github-actions

    @wannT-1 已认领该 Issue,并已自动设为 Assignee。提交 PR 时请在描述中写 Closes #409。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

claimedClaimed by a contributor and currently in progress

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions