I’ve released the first public alpha of the Universal Amount Standard API (UAS):

GitHub: https://github.com/payfrit/payfrit-uas

UAS is a standalone, dependency-free PHP reference API for representing and calculating monetary amounts without relying on binary floating-point numbers. It also prevents malformed displays such as 500$ by separating the amount, currency, and locale. Any website or app can let users select a preferred currency and render the value correctly as $500, ₹500, ₱500, or 500 €.

The core idea is simple: amounts are represented as canonical decimal strings with eight fractional places:

{ "amount": "12.34000000" } 

The release includes:

  • Exact decimal-safe addition, subtraction, multiplication, and division
  • Canonical amount normalization
  • Explicit-rate currency conversion
  • Currency metadata and decimal-place information
  • A machine-readable JSON Schema
  • A browser-based interactive demo
  • PHP 8.1+ support with no external dependencies
  • MIT licensing

Example:

curl -X POST http://127.0.0.1:8080/v1/amounts/normalize \ -H 'Content-Type: application/json' \ -d '{"amount":"12.34"}' 

Returns:

{"ok":true,"data":{"amount":"12.34000000"}} 

The project is intended as a foundational amount type that can be used by payment, pricing, wallet, payout, fee, allocation, and commerce systems. Currency is contextual rather than baked into the amount itself, so the same type can represent a business price, wallet balance, settlement amount, or display value without conflating those roles.

This is explicitly an alpha developer release. It does not currently provide persistence, authentication, hosted uptime, live exchange-rate synchronization, request limits, or server-side localization. Exchange rates must be supplied explicitly by the caller.

I’d especially appreciate feedback on:

  • Whether eight decimal places is a useful default contract
  • Currency-context modeling
  • Conversion and rounding semantics
  • API shape and naming
  • Interoperability with existing money/value-object libraries

To run it locally:

git clone https://github.com/payfrit/payfrit-uas.git cd payfrit-uas php tests.php php -S 127.0.0.1:8080 -t public public/index.php 

Then visit http://127.0.0.1:8080/demo.html.

Feedback and criticism welcome:

https://github.com/payfrit/payfrit-uas

submitted by /u/payfrit
[link] [留言]