Skip to content

FormattingAndParsing

Business Purpose

Provides flexible, locale-aware printing and parsing of monetary amounts to/from strings, with full control over grouping, decimal symbols, sign, and currency representation. [AI Inference] This enables internationalization and custom formatting in user interfaces or reports.

Current Behaviors

Technical Implementation

  • MoneyFormatter MoneyFormatter.java:58 and MoneyFormatterBuilder MoneyFormatterBuilder.java:61 are IMMUTABLE_VALUE_OBJECT (design patterns detected).
  • The builder creates a chain of printer-parsers, each implementing the same internal interface (e.g., AmountPrinterParser, LiteralPrinterParser).
  • AmountPrinterParser uses @Override at lines 46, 129, 180.
  • MoneyParseContext tracks parsing progress and allows child contexts for nesting MoneyParseContext.java:267.
  • MoneyAmountStyle supports localization with localize(Locale) MoneyAmountStyle.java:225.

Definition of Done

  • A formatter built with appendCurrencyCode().appendAmount() prints "USD 12.34" for a Money of USD 12.34.
  • MoneyFormatter.parseMoney("GBP 5.00") returns a Money with GBP and amount 5.00.
  • Changing MoneyAmountStyle grouping character from comma to space alters the printed output accordingly.
  • Parsing an incomplete input like "JPY 123" with missing minor digits throws MoneyFormatException.
  • The appendSigned method prints a negative sign only for negative amounts and no sign for positive.
  • MoneyPrintContext.getLocale() returns the locale set by MoneyFormatter.withLocale().