Expand description
§Chinese Number
Convert primitive numbers to Chinese numbers, or parse Chinese numbers to primitive numbers.
This crate can convert Rust’s primitive number data types to Chinese numbers as strings. For example, 123 can be converted into 一二三, 一百二十三 or 壹佰貳拾參. It supports both Traditional Chinese and Simple Chinese, and it supports different methods to count the scale as well. Also, Chinese numbers in strings can be parsed to primitive number data types.
§Example
use chinese_number::{ChineseCase, ChineseCountMethod, ChineseVariant, NumberToChinese, ChineseToNumber};
assert_eq!("一二三", 123i8.to_chinese_naive(ChineseVariant::Traditional, ChineseCase::Lower));
assert_eq!("壹佰貳拾參", 123i8.to_chinese(ChineseVariant::Traditional, ChineseCase::Upper, ChineseCountMethod::TenThousand).unwrap());
assert_eq!("壹佰贰拾叁", 123i8.to_chinese(ChineseVariant::Simple, ChineseCase::Upper, ChineseCountMethod::TenThousand).unwrap());
assert_eq!("一百二十三", 123i8.to_chinese(ChineseVariant::Traditional, ChineseCase::Lower, ChineseCountMethod::TenThousand).unwrap());
assert_eq!("一極二載三正四澗五溝六穰七秭八垓九京零一億二萬三千四百五十六", 1234567890123456i64.to_chinese(ChineseVariant::Traditional, ChineseCase::Lower, ChineseCountMethod::Low).unwrap());
assert_eq!("十二穰三千四百五十六秭七千八百九十垓一千二百三十四京五千六百七十八兆九千零一十二億三千四百五十六萬七千八百九十", 123456789012345678901234567890i128.to_chinese(ChineseVariant::Traditional, ChineseCase::Lower, ChineseCountMethod::TenThousand).unwrap());
assert_eq!("十二萬三千四百五十六京七千八百九十萬一千二百三十四兆五千六百七十八萬九千零一十二億三千四百五十六萬七千八百九十", 123456789012345678901234567890i128.to_chinese(ChineseVariant::Traditional, ChineseCase::Lower, ChineseCountMethod::Middle).unwrap());
assert_eq!("十二萬三千四百五十六億七千八百九十萬一千二百三十四兆五千六百七十八萬九千零一十二億三千四百五十六萬七千八百九十", 123456789012345678901234567890i128.to_chinese(ChineseVariant::Traditional, ChineseCase::Lower, ChineseCountMethod::High).unwrap());
assert_eq!("一角二分", 0.12f64.to_chinese(ChineseVariant::Traditional, ChineseCase::Lower, ChineseCountMethod::TenThousand).unwrap());
assert_eq!(123i8, "一二三".to_number_naive().unwrap());
assert_eq!(123i8, "一百二十三".to_number(ChineseCountMethod::TenThousand).unwrap());
assert_eq!(-30303i16, "負三萬零三百零三".to_number(ChineseCountMethod::TenThousand).unwrap());
assert_eq!(3212345678u32, "三十二億一千二百三十四萬五千六百七十八".to_number(ChineseCountMethod::TenThousand).unwrap());
assert_eq!(10010001001001001000u64, "一千零一京零一兆零一十億零一百萬一千".to_number(ChineseCountMethod::TenThousand).unwrap());
assert_eq!(1000000u64, "一兆".to_number(ChineseCountMethod::Low).unwrap());
assert_eq!(1000000000000u64, "一兆".to_number(ChineseCountMethod::TenThousand).unwrap());
assert_eq!(10000000000000000u64, "一兆".to_number(ChineseCountMethod::Middle).unwrap());
assert_eq!(10000000000000000u64, "一兆".to_number(ChineseCountMethod::High).unwrap());
assert_eq!(120u64, "一百二".to_number(ChineseCountMethod::TenThousand).unwrap());
assert_eq!(2300u64, "兩千三".to_number(ChineseCountMethod::TenThousand).unwrap());
assert_eq!(34000u64, "三萬四".to_number(ChineseCountMethod::TenThousand).unwrap());
assert_eq!(105000u64, "十萬五".to_number(ChineseCountMethod::TenThousand).unwrap());
assert_eq!(150000000u64, "一億五".to_number(ChineseCountMethod::TenThousand).unwrap());§No Std
Disable the default features to compile this crate without std.
[dependencies.chinese-number]
version = "*"
default-features = false
features = ["number-to-chinese", "chinese-to-number"]Enums§
- Chinese
Case - 大寫或小寫數字。
- Chinese
Count Method - 根據 五經算術 將大的單位分為 上數 (
High)、中數 (Middle)、下數 (Low) 三種類型,再加上現代使用的 萬進 (TenThousand)。 - Chinese
ToNumber Error chinese-to-number - 將中文數字轉成數值時發生的錯誤。
- Chinese
Variant - The different writing systems used for the Chinese language. Traditional Chinese (繁體中文) or Simple Chinese (简体中文).
- Number
ToChinese Error number-to-chinese - 將數值轉成中文數字時發生的錯誤。
Traits§
- Chinese
ToNumber chinese-to-number - 讓 Rust 程式語言的字串型別擁有將中文數字轉成數值的能力。
- Number
ToChinese number-to-chinese - 讓 Rust 程式語言的所有基本數值型別擁有轉成中文數字的能力。
Functions§
- from_
chinese_ to_ f32_ high chinese-to-number - 將中文數字轉成
f32浮點數。使用 「上數」。 - from_
chinese_ to_ f32_ low chinese-to-number - 將中文數字轉成
f32浮點數。使用 「下數」。 - from_
chinese_ to_ f32_ middle chinese-to-number - 將中文數字轉成
f32浮點數。使用 「中數」。 - from_
chinese_ to_ f32_ naive chinese-to-number - 將中文數字轉成
f32浮點數。不進行單位計算。 - from_
chinese_ to_ f32_ ten_ thousand chinese-to-number - 將中文數字轉成
f32浮點數。使用 「萬進」。 - from_
chinese_ to_ f64_ high chinese-to-number - 將中文數字轉成
f64浮點數。使用 「上數」。 - from_
chinese_ to_ f64_ low chinese-to-number - 將中文數字轉成
f64浮點數。使用 「下數」。 - from_
chinese_ to_ f64_ middle chinese-to-number - 將中文數字轉成
f64浮點數。使用 「中數」。 - from_
chinese_ to_ f64_ naive chinese-to-number - 將中文數字轉成
f64浮點數。不進行單位計算。 - from_
chinese_ to_ f64_ ten_ thousand chinese-to-number - 將中文數字轉成
f64浮點數。使用 「萬進」。 - from_
chinese_ to_ i8 chinese-to-number - 將中文數字轉成
i8整數。 - from_
chinese_ to_ i8_ naive chinese-to-number - 將中文數字轉成
i8整數。不進行單位計算。 - from_
chinese_ to_ i16 chinese-to-number - 將中文數字轉成
i16整數。 - from_
chinese_ to_ i16_ naive chinese-to-number - 將中文數字轉成
i16整數。不進行單位計算。 - from_
chinese_ to_ i32_ high chinese-to-number - 將中文數字轉成
i32整數。使用 「上數」。 - from_
chinese_ to_ i32_ low chinese-to-number - 將中文數字轉成
i32整數。使用 「下數」。 - from_
chinese_ to_ i32_ middle chinese-to-number - 將中文數字轉成
i32整數。使用 「中數」。 - from_
chinese_ to_ i32_ naive chinese-to-number - 將中文數字轉成
i32整數。不進行單位計算。 - from_
chinese_ to_ i32_ ten_ thousand chinese-to-number - 將中文數字轉成
i32整數。使用 「萬進」。 - from_
chinese_ to_ i64_ high chinese-to-number - 將中文數字轉成
i64整數。使用 「上數」。 - from_
chinese_ to_ i64_ low chinese-to-number - 將中文數字轉成
i64整數。使用 「下數」。 - from_
chinese_ to_ i64_ middle chinese-to-number - 將中文數字轉成
i64整數。使用 「中數」。 - from_
chinese_ to_ i64_ naive chinese-to-number - 將中文數字轉成
i64整數。不進行單位計算。 - from_
chinese_ to_ i64_ ten_ thousand chinese-to-number - 將中文數字轉成
i64整數。使用 「萬進」。 - from_
chinese_ to_ i128_ high chinese-to-number - 將中文數字轉成
i128整數。使用 「上數」。 - from_
chinese_ to_ i128_ low chinese-to-number - 將中文數字轉成
i128整數。使用 「下數」。 - from_
chinese_ to_ i128_ middle chinese-to-number - 將中文數字轉成
i128整數。使用 「中數」。 - from_
chinese_ to_ i128_ naive chinese-to-number - 將中文數字轉成
i128整數。不進行單位計算。 - from_
chinese_ to_ i128_ ten_ thousand chinese-to-number - 將中文數字轉成
i128整數。使用 「萬進」。 - from_
chinese_ to_ isize_ high chinese-to-number - 將中文數字轉成
isize整數。使用 「上數」。 - from_
chinese_ to_ isize_ low chinese-to-number - 將中文數字轉成
isize整數。使用 「下數」。 - from_
chinese_ to_ isize_ middle chinese-to-number - 將中文數字轉成
isize整數。使用 「中數」。 - from_
chinese_ to_ isize_ naive chinese-to-number - 將中文數字轉成
isize整數。不進行單位計算。 - from_
chinese_ to_ isize_ ten_ thousand chinese-to-number - 將中文數字轉成
isize整數。使用 「萬進」。 - from_
chinese_ to_ u8 chinese-to-number - 將中文數字轉成
u8整數。 - from_
chinese_ to_ u8_ naive chinese-to-number - 將中文數字轉成
u8整數。不進行單位計算。 - from_
chinese_ to_ u16 chinese-to-number - 將中文數字轉成
u16整數。 - from_
chinese_ to_ u16_ naive chinese-to-number - 將中文數字轉成
u16整數。不進行單位計算。 - from_
chinese_ to_ u32_ high chinese-to-number - 將中文數字轉成
u32整數。使用 「上數」。 - from_
chinese_ to_ u32_ low chinese-to-number - 將中文數字轉成
u32整數。使用 「下數」。 - from_
chinese_ to_ u32_ middle chinese-to-number - 將中文數字轉成
u32整數。使用 「中數」。 - from_
chinese_ to_ u32_ naive chinese-to-number - 將中文數字轉成
u32整數。不進行單位計算。 - from_
chinese_ to_ u32_ ten_ thousand chinese-to-number - 將中文數字轉成
u32整數。使用 「萬進」。 - from_
chinese_ to_ u64_ high chinese-to-number - 將中文數字轉成
u64整數。使用 「上數」。 - from_
chinese_ to_ u64_ low chinese-to-number - 將中文數字轉成
u64整數。使用 「下數」。 - from_
chinese_ to_ u64_ middle chinese-to-number - 將中文數字轉成
u64整數。使用 「中數」。 - from_
chinese_ to_ u64_ naive chinese-to-number - 將中文數字轉成
u64整數。不進行單位計算。 - from_
chinese_ to_ u64_ ten_ thousand chinese-to-number - 將中文數字轉成
u64整數。使用 「萬進」。 - from_
chinese_ to_ u128_ high chinese-to-number - 將中文數字轉成
u128整數。使用 「上數」。 - from_
chinese_ to_ u128_ low chinese-to-number - 將中文數字轉成
u128整數。使用 「下數」。 - from_
chinese_ to_ u128_ middle chinese-to-number - 將中文數字轉成
u128整數。使用 「中數」。 - from_
chinese_ to_ u128_ naive chinese-to-number - 將中文數字轉成
u128整數。不進行單位計算。 - from_
chinese_ to_ u128_ ten_ thousand chinese-to-number - 將中文數字轉成
u128整數。使用 「萬進」。 - from_
chinese_ to_ usize_ high chinese-to-number - 將中文數字轉成
usize整數。使用 「上數」。 - from_
chinese_ to_ usize_ low chinese-to-number - 將中文數字轉成
usize整數。使用 「下數」。 - from_
chinese_ to_ usize_ middle chinese-to-number - 將中文數字轉成
usize整數。使用 「中數」。 - from_
chinese_ to_ usize_ naive chinese-to-number - 將中文數字轉成
usize整數。不進行單位計算。 - from_
chinese_ to_ usize_ ten_ thousand chinese-to-number - 將中文數字轉成
usize整數。使用 「萬進」。 - from_
f32_ to_ chinese_ high number-to-chinese - 將
f32浮點數轉成中文數字,使用 「上數」。 - from_
f32_ to_ chinese_ low number-to-chinese - 將
f32浮點數轉成中文數字,使用 「下數」。數值的絕對值不能大於或等於1_0000_0000_0000_0000。 - from_
f32_ to_ chinese_ middle number-to-chinese - 將
f32浮點數轉成中文數字,使用 「中數」。 - from_
f32_ to_ chinese_ naive number-to-chinese - 將
f32整數轉成中文數字,不進行單位計算。 - from_
f32_ to_ chinese_ ten_ thousand number-to-chinese - 將
f32浮點數轉成中文數字,使用 「萬進」。 - from_
f64_ to_ chinese_ high number-to-chinese - 將
f64浮點數轉成中文數字,使用 「上數」。 - from_
f64_ to_ chinese_ low number-to-chinese - 將
f64浮點數轉成中文數字,使用 「下數」。數值的絕對值不能大於或等於1_0000_0000_0000_0000。 - from_
f64_ to_ chinese_ middle number-to-chinese - 將
f64浮點數轉成中文數字,使用 「中數」。數值的絕對值不能大於或等於1e96。 - from_
f64_ to_ chinese_ naive number-to-chinese - 將
f64浮點數轉成中文數字,不進行單位計算。 - from_
f64_ to_ chinese_ ten_ thousand number-to-chinese - 將
f64浮點數轉成中文數字,使用 「萬進」。數值的絕對值不能大於或等於1e52。 - from_
i8_ to_ chinese number-to-chinese - 將
i8整數轉成中文數字。 - from_
i8_ to_ chinese_ naive number-to-chinese - 將
i8整數轉成中文數字。不進行單位計算。 - from_
i16_ to_ chinese number-to-chinese - 將
i16整數轉成中文數字。 - from_
i16_ to_ chinese_ naive number-to-chinese - 將
i16整數轉成中文數字。不進行單位計算。 - from_
i32_ to_ chinese_ high number-to-chinese - 將
i32整數轉成中文數字,使用 「上數」。 - from_
i32_ to_ chinese_ low number-to-chinese - 將
i32整數轉成中文數字,使用 「下數」。 - from_
i32_ to_ chinese_ middle number-to-chinese - 將
i32整數轉成中文數字,使用 「中數」。 - from_
i32_ to_ chinese_ naive number-to-chinese - 將
i32整數轉成中文數字。不進行單位計算。 - from_
i32_ to_ chinese_ ten_ thousand number-to-chinese - 將
i32整數轉成中文數字,使用 「萬進」。 - from_
i64_ to_ chinese_ high number-to-chinese - 將
i64整數轉成中文數字,使用 「上數」。 - from_
i64_ to_ chinese_ low number-to-chinese - 將
i64整數轉成中文數字,使用 「下數」。數值的絕對值不能大於或等於1_0000_0000_0000_0000。 - from_
i64_ to_ chinese_ middle number-to-chinese - 將
i64整數轉成中文數字,使用 「中數」。 - from_
i64_ to_ chinese_ naive number-to-chinese - 將
i64整數轉成中文數字。不進行單位計算。 - from_
i64_ to_ chinese_ ten_ thousand number-to-chinese - 將
i64整數轉成中文數字,使用 「萬進」。 - from_
i128_ to_ chinese_ high number-to-chinese - 將
i128整數轉成中文數字,使用 「上數」。 - from_
i128_ to_ chinese_ low number-to-chinese - 將
i128整數轉成中文數字,使用 「下數」。數值的絕對值不能大於或等於1_0000_0000_0000_0000。 - from_
i128_ to_ chinese_ middle number-to-chinese - 將
i128整數轉成中文數字,使用 「中數」。 - from_
i128_ to_ chinese_ naive number-to-chinese - 將
i128整數轉成中文數字,不進行單位計算。 - from_
i128_ to_ chinese_ ten_ thousand number-to-chinese - 將
i128整數轉成中文數字,使用 「萬進」。 - from_
isize_ to_ chinese_ high number-to-chinese - 將
isize整數轉成中文數字,使用 「上數」。 - from_
isize_ to_ chinese_ low number-to-chinese - 將
isize整數轉成中文數字,使用 「下數」。數值的絕對值不能大於或等於1_0000_0000_0000_0000。 - from_
isize_ to_ chinese_ middle number-to-chinese - 將
isize整數轉成中文數字,使用 「中數」。 - from_
isize_ to_ chinese_ naive number-to-chinese - 將
isize整數轉成中文數字,不進行單位計算。 - from_
isize_ to_ chinese_ ten_ thousand number-to-chinese - 將
isize整數轉成中文數字,使用 「萬進」。 - from_
u8_ to_ chinese number-to-chinese - 將
u8整數轉成中文數字。 - from_
u8_ to_ chinese_ naive number-to-chinese - 將
u8整數轉成中文數字,不進行單位計算。 - from_
u16_ to_ chinese number-to-chinese - 將
u16整數轉成中文數字。 - from_
u16_ to_ chinese_ naive number-to-chinese - 將
u16整數轉成中文數字,不進行單位計算。 - from_
u32_ to_ chinese_ high number-to-chinese - 將
u32整數轉成中文數字,使用 「上數」。 - from_
u32_ to_ chinese_ low number-to-chinese - 將
u32整數轉成中文數字,使用 「下數」。 - from_
u32_ to_ chinese_ middle number-to-chinese - 將
u32整數轉成中文數字,使用 「中數」。 - from_
u32_ to_ chinese_ naive number-to-chinese - 將
u32整數轉成中文數字,不進行單位計算。 - from_
u32_ to_ chinese_ ten_ thousand number-to-chinese - 將
u32整數轉成中文數字,使用 「萬進」。 - from_
u64_ to_ chinese_ high number-to-chinese - 將
u64整數轉成中文數字,使用 「上數」。 - from_
u64_ to_ chinese_ low number-to-chinese - 將
u64整數轉成中文數字,使用 「下數」。數值不能大於或等於1_0000_0000_0000_0000。 - from_
u64_ to_ chinese_ middle number-to-chinese - 將
u64整數轉成中文數字,使用 「中數」。 - from_
u64_ to_ chinese_ naive number-to-chinese - 將
u32整數轉成中文數字,不進行單位計算。 - from_
u64_ to_ chinese_ ten_ thousand number-to-chinese - 將
u64整數轉成中文數字,使用 「萬進」。 - from_
u128_ to_ chinese_ high number-to-chinese - 將
u128整數轉成中文數字,使用 「上數」。 - from_
u128_ to_ chinese_ low number-to-chinese - 將
u128整數轉成中文數字,使用 「下數」。數值不能大於或等於1_0000_0000_0000_0000。 - from_
u128_ to_ chinese_ middle number-to-chinese - 將
u128整數轉成中文數字,使用 「中數」。 - from_
u128_ to_ chinese_ naive number-to-chinese - 將
u128整數轉成中文數字,不進行單位計算。 - from_
u128_ to_ chinese_ ten_ thousand number-to-chinese - 將
u128整數轉成中文數字,使用 「萬進」。 - from_
usize_ to_ chinese_ high number-to-chinese - 將
usize整數轉成中文數字,使用 「上數」。 - from_
usize_ to_ chinese_ low number-to-chinese - 將
usize整數轉成中文數字,使用 「下數」。數值不能大於或等於1_0000_0000_0000_0000。 - from_
usize_ to_ chinese_ middle number-to-chinese - 將
usize整數轉成中文數字,使用 「中數」。 - from_
usize_ to_ chinese_ naive number-to-chinese - 將
usize整數轉成中文數字,不進行單位計算。 - from_
usize_ to_ chinese_ ten_ thousand number-to-chinese - 將
usize整數轉成中文數字,使用 「萬進」。