Skip to content

Architecture [Needs Review]: Integer minor-unit Money foundation (main/core/money.ts) #285

Description

@khaira777

Important

Status: Needs Architectural Review
This issue outlines a proposed core architectural change. It requires technical review and approval before deciding whether to implement or adopt.

Extracted from fork richanonymous22/FloCafe (branch: claude/plemmo-epos-audit-fro8v9):

Overview

Replace floating-point currency math in standard JavaScript numbers (0.1 + 0.2 = 0.30000000000000004) with a deterministic, integer-minor-unit Money library (main/core/money.ts).

Key Features & Technical Details

  1. Integer Minor-Unit Storage:
    • Stores all monetary values in minor units (e.g. cents, pence, paise: $19.99 = 1999).
  2. Banker’s Rounding (ROUND_HALF_EVEN):
    • Uses standard accounting Banker’s Rounding on exact halves to eliminate systemic upward rounding bias over large volumes of sales.
  3. Penny-Safe split() Distribution:
    • Safely divides totals without penny-loss discrepancies (e.g. splitting $10.00 three ways yields [$3.34, $3.33, $3.33] totaling $10.00 exactly).
  4. Reference Implementation:
    • main/core/money.ts & tests/plemmo-money.test.ts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:backendBackend (Express/SQLite)enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions