Class ThaiConvertHandler

java.lang.Object
io.github.zazalng.handler.ThaiConvertHandler

@Deprecated public final class ThaiConvertHandler extends Object
Deprecated.
Internal Thai language converter for converting numeric amounts to Thai Baht text.

This package-private handler implements the specialized logic for converting BigDecimal amounts to their Thai textual representation. It is not intended for direct use; instead, access through the public ThaiBaht API.

Thai Grammar Rules Implemented

This converter implements comprehensive Thai numerical grammar including:

  • "เอ็ด" (edt): Used for the ones digit in compound numbers (e.g., 101 = "หนึ่งร้อยเอ็ด", 21 = "ยี่สิบเอ็ด" but NOT 1 alone)
  • "ยี่" (yee): Special form for twenty (20 = "ยี่สิบ") and for twenties in compound numbers (120 = "หนึ่งร้อยยี่สิบ")
  • Silent "หนึ่ง" (1): In tens position, 10 is "สิบ" not "หนึ่งสิบ"
  • Repeating "ล้าน" (millions): Large numbers repeat the word "ล้าน" for groups of millions (e.g., 1,000,000 = "หนึ่งล้าน", 1,000,001,000 = "หนึ่งล้านหนึ่งล้าน")

Conversion Process

The conversion follows these high-level steps:

  1. Normalize amount to 2 decimal places using RoundingMode.DOWN
  2. Extract absolute value to handle magnitude separately
  3. Split into integer (baht) and fractional (satang) parts
  4. Convert each part using specialized Thai digit conversion methods
  5. Apply configuration options (unit words, custom format)
  6. Handle negative prefix if amount is negative

Number Conversion Methods

The converter uses specialized methods for different numeric ranges:

  • convertThaiInteger(): Handles full integers including millions (recursively handles millions and remainder)
  • convertThaiUnderMillion(): Handles 1-999,999 using positional system (แสน, หมื่น, พัน, ร้อย, สิบ, หน่วย)
  • convertThaiTwoDigits(): Handles 1-99 for satang conversion (special handling for tens)

Satang Handling

Satang (fractional part) is handled as follows:

  • When satang = 0: Output "ถ้วน" (Only/Exact) if units are enabled
  • When satang > 0: Convert using specialized two-digit converter and append "สตางค์"
  • Uses RoundingMode.DOWN for truncation (100.999 → 100.99)

Configuration Support

This handler respects all ThaiBahtConfig options:

  • Unit words inclusion (บาท, สตางค์, ถ้วน)
  • Custom format templates via FormatApplier
  • Negative prefix configuration (defaults to "ลบ" for Thai)
  • Formal wording mode (reserved for future use)

Examples

Thai conversion examples:


 // With units enabled (default)
 "100.00"  → "หนึ่งร้อยบาทถ้วน"     (hundred baht exact)
 "101.01"  → "หนึ่งร้อยเอ็ดบาทหนึ่งสตางค์"  (hundred one baht one satang)
 "1234.56" → "หนึ่งพันสองร้อยสามสิบสี่บาทห้าสิบหกสตางค์"

 // Without units
 "100.00"  → "หนึ่งร้อย"
 "1000.50" → "หนึ่งพันห้าสิบ"
 
Since:
1.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.