money-decimal-arithmetic

Implement integer minor unit arithmetic and largest-remainder allocation for monetary calculations.

9|3|Updated Jun 13, 2026
One-click install
npx skills add https://github.com/Sir-chawakorn/sanook-cli --skill money-decimal-arithmetic
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: money-decimal-arithmetic
Source: https://github.com/Sir-chawakorn/sanook-cli/tree/main/skills/money-decimal-arithmetic
Command: npx skills add https://github.com/Sir-chawakorn/sanook-cli --skill money-decimal-arithmetic

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill resolves common financial calculation errors such as off-by-a-penny totals, rounding inconsistencies, and precision loss caused by using binary floating-point numbers for monetary values.

Core Features & Use Cases

  • Precision Arithmetic: Implements integer minor units or arbitrary-precision decimals to ensure exact calculations for prices, taxes, and discounts.
  • Largest-Remainder Allocation: Ensures that splitting charges across line items sums exactly to the original total without leaking pennies.
  • ISO 4217 Compliance: Handles per-currency exponents correctly, ensuring that currencies like JPY (0 exponent) and BHD (3 exponents) are treated differently than USD.

Quick Start

Use the money-decimal-arithmetic skill to refactor the current pricing logic to use integer minor units and implement a largest-remainder allocation for the invoice split.

Frequently Asked Questions about money-decimal-arithmetic

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does my financial calculation have off-by-a-penny errors and how do I fix it?

Off-by-a-penny errors occur because binary floating-point numbers lose precision during monetary arithmetic. You fix this by refactoring calculations to use integer minor units or arbitrary-precision decimals, ensuring exact reconciliation invariants.

What is the largest-remainder allocation method for splitting invoice totals?

Largest-remainder allocation is a technique that distributes remaining pennies across line items so the split sums exactly to the original total. It prevents precision loss and leaking pennies when dividing charges across multiple entries.

How do I handle currency-aware rounding for different ISO 4217 exponents?

Handle currency-aware rounding by applying ISO 4217 exponent rules per currency, treating JPY with a 0 exponent differently than USD with 2 or BHD with 3. This ensures correct minor unit calculations across global currencies.

How do I prevent float precision loss when calculating taxes and discounts?

Prevent float precision loss by replacing floating-point numbers with integer minor units or arbitrary-precision decimals for all tax and discount calculations. This ensures exact pricing logic and eliminates rounding inconsistencies.

Do I need arbitrary-precision decimal libraries to avoid float drift in accounting software?

You need either arbitrary-precision decimal types or strict integer minor units to avoid float drift in accounting software. Binary floating-point numbers cannot accurately represent decimal fractions, causing reconciliation failures.

What is the best way to ensure exact allocation when splitting charges across line items?

The best way to ensure exact allocation is implementing a largest-remainder strategy that distributes leftover pennies across line items. This guarantees the split totals sum exactly to the original charge without leaking pennies.