Expand description
Thai number normalization.
Two independent normalization paths:
-
Thai digit → ASCII: converts Thai digit characters (๐–๙, U+0E50–U+0E59) to their ASCII equivalents. Non-digit characters are passed through unchanged.
-
Spelled-out Thai number words → integer: parses a full Thai cardinal number word (e.g.
หนึ่งร้อยยี่สิบสาม) into its numeric value (123).
§Thai digit mapping
| Thai | ASCII |
|---|---|
| ๐ | 0 |
| ๑ | 1 |
| ๒ | 2 |
| ๓ | 3 |
| ๔ | 4 |
| ๕ | 5 |
| ๖ | 6 |
| ๗ | 7 |
| ๘ | 8 |
| ๙ | 9 |
§Thai number word grammar (cardinal)
| Word | Value | Notes |
|---|---|---|
| ศูนย์ | 0 | |
| หนึ่ง | 1 | |
| เอ็ด | 1 | units position after สิบ only |
| ยี่ | 2 | tens position only (ยี่สิบ = 20) |
| สอง | 2 | |
| สาม | 3 | |
| สี่ | 4 | |
| ห้า | 5 | |
| หก | 6 | |
| เจ็ด | 7 | |
| แปด | 8 | |
| เก้า | 9 | |
| สิบ | ×10 | preceding digit optional (default 1) |
| ร้อย | ×100 | preceding digit optional |
| พัน | ×1 000 | preceding digit optional |
| หมื่น | ×10 000 | preceding digit optional |
| แสน | ×100 000 | preceding digit optional |
| ล้าน | ×1 000 000 | splits number into two sub-million groups |
§Examples
use kham_core::number::{thai_digits_to_ascii, parse_thai_word};
// Thai digit conversion
assert_eq!(thai_digits_to_ascii("๑๒๓"), "123");
assert_eq!(thai_digits_to_ascii("ธนาคาร๑๐๐แห่ง"), "ธนาคาร100แห่ง");
// Spelled-out number word parsing
assert_eq!(parse_thai_word("ยี่สิบ"), Some(20));
assert_eq!(parse_thai_word("หนึ่งร้อยยี่สิบสาม"), Some(123));
assert_eq!(parse_thai_word("สองล้านห้าแสน"), Some(2_500_000));Structs§
- Baht
Amount - A monetary amount in Thai Baht.
Functions§
- is_
thai_ digit_ str - Return
trueif every character intextis a Thai digit (๐–๙). - parse_
thai_ baht - Parse a Thai Baht currency string into a
BahtAmount. - parse_
thai_ word - Parse a spelled-out Thai cardinal number word into its numeric value.
- thai_
digit_ to_ ascii - Convert a single Thai digit character (๐–๙) to its ASCII equivalent.
- thai_
digits_ to_ ascii - Convert all Thai digit characters in
textto ASCII digits. - thai_
word_ to_ decimal - Return the decimal string representation of a Thai number word, or
Noneif the input is not a recognised Thai number word. - to_
thai_ baht_ text - Render a baht + satang amount as Thai currency text.
- u64_
to_ thai_ word - Convert a
u64to a spelled-out Thai cardinal number word.