Skip to content

lineItemNormalizer.ts: Fix rounding error when normalizing amounts with 7 decimal places #654

Description

@Kingsman-99

Description

src/lineItemNormalizer.ts normalizes line-item amounts to 2 decimal places using JavaScript floating-point arithmetic, which introduces rounding errors for values with 7 significant decimal places (Stellar's native precision). The fix should use integer arithmetic in stroops.

Acceptance Criteria

  • Amount normalization converts to stroops (integer), rounds, then converts back to decimal string
  • normalize(0.0000001) returns '0.00' and normalize(0.0000005) returns '0.00' (document the rounding choice used)
  • A regression test covers a value that previously produced an incorrect result
  • Unit tests pass

Context

  • Target file: src/lineItemNormalizer.ts
  • Do not use BigDecimal libraries; use BigInt arithmetic

Activity

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions