Crate chinese_number

source ·
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.

Example

extern crate chinese_number;

use chinese_number::{ChineseNumber, ChineseVariant, ChineseNumberToNumber, ChineseBigNumberCountMethod};

assert_eq!("壹佰貳拾參", 123i8.to_uppercase_ten_thousand(ChineseVariant::Traditional));
assert_eq!("壹佰贰拾参", 123i8.to_uppercase_ten_thousand(ChineseVariant::Simple));

assert_eq!("一百二十三", 123i8.to_lowercase_ten_thousand(ChineseVariant::Traditional));

assert_eq!("十二萬三千四百五十六億七千八百九十萬一千二百三十四兆五千六百七十八萬九千零一十二億三千四百五十六萬七千八百九十", 123456789012345678901234567890i128.to_lowercase_high(ChineseVariant::Traditional));
assert_eq!("十二萬三千四百五十六京七千八百九十萬一千二百三十四兆五千六百七十八萬九千零一十二億三千四百五十六萬七千八百九十", 123456789012345678901234567890i128.to_lowercase_middle(ChineseVariant::Traditional));
assert_eq!("十二穰三千四百五十六秭七千八百九十垓一千二百三十四京五千六百七十八兆九千零一十二億三千四百五十六萬七千八百九十", 123456789012345678901234567890i128.to_lowercase_ten_thousand(ChineseVariant::Traditional));
assert_eq!("一极二载三正四涧五沟六穰七秭八垓九京零一亿二万三千四百五十六", 1234567890123456i64.to_lowercase_low(ChineseVariant::Simple));

assert_eq!("一角二分", 0.12f64.to_lowercase_ten_thousand(ChineseVariant::Traditional));

assert_eq!(123i8, "一百二十三".parse_chinese_number(ChineseBigNumberCountMethod::TenThousand).unwrap());
assert_eq!(-30303i16, "負三萬零三百零三".parse_chinese_number(ChineseBigNumberCountMethod::TenThousand).unwrap());
assert_eq!(3212345678u32, "三十二億一千二百三十四萬五千六百七十八".parse_chinese_number(ChineseBigNumberCountMethod::TenThousand).unwrap());
assert_eq!(10010001001001001000u64, "一千零一京零一兆零一十億零一百萬一千".parse_chinese_number(ChineseBigNumberCountMethod::TenThousand).unwrap());

assert_eq!(1000000u64, "一兆".parse_chinese_number(ChineseBigNumberCountMethod::Low).unwrap());
assert_eq!(1000000000000u64, "一兆".parse_chinese_number(ChineseBigNumberCountMethod::TenThousand).unwrap());
assert_eq!(10000000000000000u64, "一兆".parse_chinese_number(ChineseBigNumberCountMethod::Middle).unwrap());
assert_eq!(10000000000000000u64, "一兆".parse_chinese_number(ChineseBigNumberCountMethod::High).unwrap());

Enums

根據 五經算術 將大的單位分為上數、中數、下數三種類型,再加上現代使用的萬進。
大寫或小寫數字。
繁體中文(Traditional Chinese)或簡體中文(Simple Chinese)。

Traits

讓Rust程式語言的所有基本數值型別擁有中文數字的轉換能力。
讓Rust程式語言的字串型別擁有中文數字的轉換能力。

Functions

將f32浮點數轉成中文數字。如果使用 「下數」 來作為單位標準,數值不能大於或等於10000000000000000。
將f32浮點數轉成中文數字。如果使用 「下數」 來作為單位標準,數值不能大於或等於10000000000000000。
將f64浮點數轉成中文數字。如果使用 「下數」 來作為單位標準,數值不能大於或等於10000000000000000。
將f64浮點數轉成中文數字。如果使用 「下數」 來作為單位標準,數值不能大於或等於10000000000000000。
將i8整數轉成中文數字。
將i8整數轉成中文數字。
將i16整數轉成中文數字。
將i16整數轉成中文數字。
將i32整數轉成中文數字。
將i32整數轉成中文數字。
將i64整數轉成中文數字。如果使用 「下數」 來作為單位標準,數值不能大於或等於10000000000000000。
將i64整數轉成中文數字。如果使用 「下數」 來作為單位標準,數值不能大於或等於10000000000000000。
將i128整數轉成中文數字。如果使用 「下數」 來作為單位標準,數值不能大於或等於10000000000000000。
將i128整數轉成中文數字。如果使用 「下數」 來作為單位標準,數值不能大於或等於10000000000000000。
將isize整數轉成中文數字。
將isize整數轉成中文數字。
將u8整數轉成中文數字。
將u8整數轉成中文數字。
將u16整數轉成中文數字。
將u16整數轉成中文數字。
將u32整數轉成中文數字。
將u32整數轉成中文數字。
將u64整數轉成中文數字。如果使用 「下數」 來作為單位標準,數值不能大於或等於10000000000000000。
將u64整數轉成中文數字。如果使用 「下數」 來作為單位標準,數值不能大於或等於10000000000000000。
將u128整數轉成中文數字。如果使用 「下數」 來作為單位標準,數值不能大於或等於10000000000000000。
將u128整數轉成中文數字。如果使用 「下數」 來作為單位標準,數值不能大於或等於10000000000000000。
將usize整數轉成中文數字。
將usize整數轉成中文數字。
將中文數字轉成f32數值。
將中文數字轉成f64數值。
將中文數字轉成i8數值。
將中文數字轉成i16數值。
將中文數字轉成i32數值。
將中文數字轉成i64數值。
將中文數字轉成i128數值。
將中文數字轉成isize數值。
將中文數字轉成u8數值。
將中文數字轉成u16數值。
將中文數字轉成u32數值。
將中文數字轉成u64數值。
將中文數字轉成u128數值。
將中文數字轉成usize數值。