Thai Number Text (Rust)
A minimal, no_std-compatible Rust crate for converting numbers to Thai textual representations.
Zero dependencies by default.
Features
- Integer and float conversion to Thai text
- Thai Baht currency formatting
- Accounting-style wording (ถ้วน suffix)
- Three Et (เอ็ด) modes: Colloquial, RoyalInstitute, Military
- Large number support (ล้านล้าน, ล้านล้านล้าน, ล้านล้านล้านล้าน...)
- String input for arbitrarily large numbers (beyond i64::MAX)
- Scientific notation support (9.22 × 10^37)
#![no_std]compatible (usesalloconly)- Optional
serdesupport
Installation
[]
= "1.0.0"
Feature Flags
| Feature | Description |
|---|---|
std |
Enable std (for benchmarks) |
serde |
Enable Serialize/Deserialize |
Usage
Basic Usage
use ;
let opts = new;
// Integers
assert_eq!;
assert_eq!; // Standard: no เอ็ด
// Floats
assert_eq!;
// Currency
assert_eq!;
Et Modes (เอ็ด)
use ;
// Colloquial (default): เอ็ด only when tens digit exists
// This is the common everyday usage in Thailand
let opts = new;
assert_eq!; // has tens digit
assert_eq!; // no tens digit
assert_eq!; // has tens digit
// RoyalInstitute (ราชบัณฑิตยสภา): Always use เอ็ด for trailing 1
// This is the formal/official Thai language standard
let opts = royal_institute;
assert_eq!;
assert_eq!;
// Military: Never use เอ็ด
// Used in Thai military communications for clarity
let opts = military;
assert_eq!;
assert_eq!;
Large Numbers
use ;
let opts = new;
// Million (ล้าน)
assert_eq!;
// Trillion (ล้านล้าน)
assert_eq!;
// Quintillion (ล้านล้านล้าน) - handles up to i64::MAX
let result = to_text_i64;
// "เก้าล้านล้านล้าน..."
Accounting Style
use ;
let opts = accounting;
assert_eq!;
String Input (Arbitrarily Large Numbers)
use ;
let opts = new;
// Basic string input
assert_eq!;
assert_eq!;
// Scientific notation strings
assert_eq!;
assert_eq!;
// Beyond i64::MAX (10^24)
let result = to_text_str.unwrap;
// "หนึ่งล้านล้านล้านล้าน"
Scientific Notation
use ;
let opts = new;
// 9.22 × 10^37
assert_eq!;
// Negative exponent: 5.5 × 10^-3
assert_eq!;
Thai Language Rules
| Rule | Description | Example |
|---|---|---|
| เอ็ด (Colloquial) | Use only when tens digit exists | 101 → หนึ่งร้อยหนึ่ง |
| เอ็ด (RoyalInstitute) | Use for any trailing 1 (formal) | 101 → หนึ่งร้อยเอ็ด |
| ยี่ (yi) | Used for 2 in tens position | 20 → ยี่สิบ |
| สิบ | Omits หนึ่ง prefix for 10-19 | 10 → สิบ (not หนึ่งสิบ) |
| ล้านล้าน | Trillion (10^12) | 1,000,000,000,000 |
| ล้านล้านล้าน | Quintillion (10^18) | i64::MAX region |
API
// Direct functions (smallest code size)
;
;
;
// Generic wrapper
;
// String input (arbitrarily large numbers)
;
// Scientific notation
;
// Options
Run Demo
License
This project is MIT licensed (see LICENSE), maintaining the same license as the original work.