Package com.tuladb.currency
Class Amounts
java.lang.Object
com.tuladb.currency.Amounts
Decimal <-> minor-unit conversion.
The engine and the wire carry every amount as a long in minor
units. Only the edges speak decimals, converting with the currency's
REGISTERED scale (0-8, immutable once registered in the engine's currency
registry; see CurrencyScales). The rules are the shared contract in
contracts/amount-vectors.json, which every SDK and REST gateway is
tested against:
- parsing is exact and never rounds: more fractional digits than the
scale is refused (
too_many_decimals), zeros included; - the grammar is ASCII
digits [ '.' digits ]and nothing else: no sign, exponent, whitespace, separators, leading or trailing'.'(invalid); - the value must fit a
long(overflow); - formatting writes exactly
scalefractional digits and a leading'-'for a negative value.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intLargest scale the engine's currency registry accepts. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatMinor(long minor, int scale) Format-1at scale 2 as"-0.01".static longParse"800.00"at scale 2 into80000.static longtoMinor(BigDecimal value, int scale) ABigDecimalheld to the same rules as its exact plain-notation text:new BigDecimal("800.000")at scale 2 is refused, a negative value is invalid.
-
Field Details
-
SCALE_MAX
public static final int SCALE_MAXLargest scale the engine's currency registry accepts.- See Also:
-
-
Method Details
-
toMinor
Parse"800.00"at scale 2 into80000. -
toMinor
ABigDecimalheld to the same rules as its exact plain-notation text:new BigDecimal("800.000")at scale 2 is refused, a negative value is invalid. Never rounds. -
formatMinor
Format-1at scale 2 as"-0.01".
-