3 releases

Uses old Rust 2015

0.1.2 Nov 30, 2015
0.1.1 Nov 30, 2015
0.1.0 Nov 30, 2015

#16 in #digit

BSD-3-Clause

6KB
94 lines

Convert a decimal number to its Chinese form.

Build Status Crates.io Version GitHub stars

See the documentation for more.


lib.rs:

Convert a decimal number to its Chinese form.

Build Status Crates.io Version GitHub stars

Examples

let s = chinese_num::to_chinese_num("121").unwrap();
assert_eq!(s, "一百二十一");
let s = chinese_num::to_chinese_num("1004000007000500").unwrap();
assert_eq!(s, "一千零四万亿零七百万零五百");
let s = chinese_num::to_chinese_num("123000520").unwrap();
assert_eq!(s, "一亿二千三百万零五百二十");
let s = chinese_num::to_chinese_num("1234070000123780000087006786520988800000").unwrap();
assert_eq!(s, "一千二百三十四万零七百亿零一十二万三千七百八十亿零八千七百亿六千七百八十六万五千二百零九亿八千八百八十万");

If the given string is not a number, or begins with "0", None is returned:

let s = chinese_num::to_chinese_num("不是数字");
assert!(s.is_none());
let s = chinese_num::to_chinese_num("020");
assert!(s.is_none());

The algorithm is taken from here: http://zhuanlan.zhihu.com/iobject/20370983.

No runtime deps