Package io.github.zazalng.handler
Class EnglishConvertHandler
java.lang.Object
io.github.zazalng.handler.EnglishConvertHandler
Deprecated.
Internal English language converter for converting numeric amounts to English Baht text.
This package-private handler implements the specialized logic for converting
BigDecimal amounts to their English textual representation. It is not intended
for direct use; instead, access through the public ThaiBaht API.
English Number Formatting Rules
This converter implements standard English number-to-word conventions:
- Hyphens for compound numbers: Twenty-Five, Ninety-Nine, etc.
- Position words: Hundred, Thousand, Million
- Capitalization: Each word starts with capital letter
- Spacing: Position words separated by spaces (e.g., "One Million Twenty Thousand")
- Zero handling: Single 0 = "Zero", portions of 0 = omitted
Conversion Process
The conversion follows these high-level steps:
- Normalize amount to 2 decimal places using
RoundingMode.DOWN - Extract absolute value to handle magnitude separately
- Split into integer (baht) and fractional (satang) parts
- Convert each part using specialized English digit conversion methods
- Apply configuration options (unit words, custom format, spaces)
- Handle negative prefix if amount is negative
Number Conversion Methods
The converter uses specialized methods for different numeric ranges:
- convertEnglishInteger(): Handles full integers including millions. Recursively processes millions and remainder.
- convertEnglishUnderMillion(): Handles 1-999,999 by separating thousands. Recursively calls under-thousand converter.
- convertEnglishUnderThousand(): Handles 1-999 by separating hundreds and remainder (using under-hundred logic).
- convertEnglishTwoDigits(): Handles 1-99 for satang conversion using proper hyphenation for compound numbers.
Satang Handling
Satang (fractional part) is handled as follows:
- When satang = 0: Output "Only" (or "Exact") if units are enabled
- When satang > 0: Convert using specialized two-digit converter and append "Satang"
- Example: 100.50 → "One Hundred Baht Fifty Satang"
- Uses
RoundingMode.DOWNfor truncation (100.999 → 100.99)
Configuration Support
This handler respects all ThaiBahtConfig options:
- Unit words inclusion (Baht, Satang, Only)
- Custom format templates via
FormatApplier - Negative prefix configuration (defaults to "Minus" for English)
- Formal wording mode (reserved for future use)
Number Examples
English number formatting:
Integer examples:
0 → "Zero"
5 → "Five"
15 → "Fifteen"
25 → "Twenty-Five"
100 → "One Hundred"
101 → "One Hundred One"
1000 → "One Thousand"
1234 → "One Thousand Two Hundred Thirty-Four"
1000000 → "One Million"
1234567 → "One Million Two Hundred Thirty-Four Thousand Five Hundred Sixty-Seven"
Currency Examples
Currency conversion examples:
// With units enabled (default)
"100.00" → "One Hundred Baht Only"
"100.01" → "One Hundred Baht One Satang"
"1234.56" → "One Thousand Two Hundred Thirty-Four Baht Fifty-Six Satang"
// Without units
"100.00" → "One Hundred"
"1000.50" → "One Thousand Fifty"
// Negative amounts
"-100.00" → "Minus One Hundred Baht Only"
- Since:
- 1.3.0
- Version:
- 1.4.0
- Author:
- Zazalng
- See Also:
- Implementation Note:
- This class is package-private and stateless. It uses static methods only. The conversion algorithm maintains no mutable state and is thread-safe.
-
Method Summary