Class Amounts

java.lang.Object
com.tuladb.currency.Amounts

public final class Amounts extends Object
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 scale fractional digits and a leading '-' for a negative value.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Largest scale the engine's currency registry accepts.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    formatMinor(long minor, int scale)
    Format -1 at scale 2 as "-0.01".
    static long
    toMinor(String text, int scale)
    Parse "800.00" at scale 2 into 80000.
    static long
    toMinor(BigDecimal value, int scale)
    A BigDecimal held to the same rules as its exact plain-notation text: new BigDecimal("800.000") at scale 2 is refused, a negative value is invalid.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SCALE_MAX

      public static final int SCALE_MAX
      Largest scale the engine's currency registry accepts.
      See Also:
  • Method Details

    • toMinor

      public static long toMinor(String text, int scale)
      Parse "800.00" at scale 2 into 80000.
    • toMinor

      public static long toMinor(BigDecimal value, int scale)
      A BigDecimal held 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

      public static String formatMinor(long minor, int scale)
      Format -1 at scale 2 as "-0.01".