Skip to main content

Module number

Module number 

Source
Expand description

Thai number normalization.

Two independent normalization paths:

  1. Thai digit → ASCII: converts Thai digit characters (๐–๙, U+0E50–U+0E59) to their ASCII equivalents. Non-digit characters are passed through unchanged.

  2. Spelled-out Thai number words → integer: parses a full Thai cardinal number word (e.g. หนึ่งร้อยยี่สิบสาม) into its numeric value (123).

§Thai digit mapping

ThaiASCII
0
1
2
3
4
5
6
7
8
9

§Thai number word grammar (cardinal)

WordValueNotes
ศูนย์0
หนึ่ง1
เอ็ด1units position after สิบ only
ยี่2tens position only (ยี่สิบ = 20)
สอง2
สาม3
สี่4
ห้า5
หก6
เจ็ด7
แปด8
เก้า9
สิบ×10preceding digit optional (default 1)
ร้อย×100preceding digit optional
พัน×1 000preceding digit optional
หมื่น×10 000preceding digit optional
แสน×100 000preceding digit optional
ล้าน×1 000 000splits 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§

BahtAmount
A monetary amount in Thai Baht.

Functions§

is_thai_digit_str
Return true if every character in text is 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 text to ASCII digits.
thai_word_to_decimal
Return the decimal string representation of a Thai number word, or None if 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 u64 to a spelled-out Thai cardinal number word.