You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
735 B

3 years ago
extension intExt on int {
String get toChinese {
String nubStr = this.toString();
if (nubStr.length > 2) {
return '';
} else if (nubStr.length > 1) {
var p1 = _getNum(nubStr, 1);
var p2 = _getNum(nubStr, 2);
if (p2 == '') {
p2 = '';
}
if (p1 == '') {
p1 = '';
}
return p1 + '' + p2;
} else {
return _getNum(nubStr, 1);
}
}
//取得某位上的数字转换为中文
String _getNum(String dig, int index) {
List<String> _chinese = ['', '', '', '', '', '', '', '', '', ''];
if (index > dig.length) {
return '';
} else {
return _chinese[int.parse(dig[index - 1])];
}
}
}