-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLong2Zh.java
More file actions
72 lines (55 loc) · 1.76 KB
/
Long2Zh.java
File metadata and controls
72 lines (55 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package algorithm.others;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* @Author: zs
* @Date: 2019/8/16 11:00
*/
public class Long2Zh {
private static final String CHINESE_NEGATIVE = "负";
private static final String CHINESE_ZERO = "零";
private static final String[] CHINESE_DIGITS = new String[]{"", "一", "二", "三", "四", "五", "六", "七", "八", "九"};
private static final String[] CHINESE_UNITS = new String[]{"", "十", "百", "千"};
private static final String[] CHINESE_GROUP_UNITS = new String[]{"", "万", "亿", "兆"};
public static void main(String[] args) {
System.out.println("position:"+enumerateDigits2(465456L));
BigDecimal b = BigDecimal.valueOf(0002342L);
System.out.println(b.longValue());
}
public static String translate(Long num){
String result;
if(num == 0){
return CHINESE_ZERO;
}
if(num < 0){
result = CHINESE_NEGATIVE;
num = -num;
}
return null;
}
// enumerateDigits();
public static Long[] enumerateDigits(Long num){
Long[] digits = new Long[String.valueOf(num).length()];
int posisiotn = 0;
while (num>0){
Long digit = num % 10;
num /= 10;
digits[posisiotn] = digit;
System.out.println(digit);
posisiotn += 1;
}
return digits;
}
public static List<Long> enumerateDigits2(Long num){
List<Long> list = new ArrayList<>();
while (num>0){
Long digit = num % 10;
num /= 10;
list.add(digit);
}
Collections.reverse(list);
return list;
}
}