Trait chinese_number::NumberToChinese
source · pub trait NumberToChinese {
// Required methods
fn to_chinese(
self,
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
method: ChineseCountMethod
) -> Result<String, NumberToChineseError>;
fn to_chinese_naive(
self,
chinese_variant: ChineseVariant,
chinese_case: ChineseCase
) -> String;
}
Available on crate feature
number-to-chinese
only.Expand description
讓 Rust 程式語言的所有基本數值型別擁有轉成中文數字的能力。
Required Methods§
sourcefn to_chinese(
self,
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
method: ChineseCountMethod
) -> Result<String, NumberToChineseError>
fn to_chinese( self, chinese_variant: ChineseVariant, chinese_case: ChineseCase, method: ChineseCountMethod ) -> Result<String, NumberToChineseError>
將數值轉成中文數字。
- 如果使用 「下數」,則數值的絕對值不能大於或等於
1_0000_0000_0000_0000
。 - 如果使用 「萬進」,則數值的絕對值不能大於或等於
1e52
。 - 如果使用 「中數」,則數值的絕對值不能大於或等於
1e96
。
範例
use chinese_number::{ChineseCase, ChineseCountMethod, ChineseVariant, NumberToChinese};
assert_eq!("一百二十三京四千五百六十七兆八千九百零一億二千三百四十五萬六千七百八十九", 1234567890123456789u64.to_chinese(ChineseVariant::Traditional, ChineseCase::Lower, ChineseCountMethod::TenThousand).unwrap());
sourcefn to_chinese_naive(
self,
chinese_variant: ChineseVariant,
chinese_case: ChineseCase
) -> String
fn to_chinese_naive( self, chinese_variant: ChineseVariant, chinese_case: ChineseCase ) -> String
將數值直接轉成中文數字,不進行單位計算。
範例
use chinese_number::{
ChineseCase, ChineseCountMethod, ChineseVariant, NumberToChinese,
};
assert_eq!(
"一二三四五六七八九",
123456789
.to_chinese_naive(ChineseVariant::Traditional, ChineseCase::Lower)
);