数字の金額から漢字への変換
- class RenMingBi {
-
- private static final char[] data = new char[] { ' ', ' ', ' ', ' ', ' ',
- ' ', ' ', ' ', ' ', ' ' };
- private static final char[] units = new char[] { ' ', ' ', ' ', ' ', ' ',
- ' ', ' ', ' ', ' ' };
-
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.println(convert(1300023));
- }
-
- public static String convert(int money) {
- StringBuffer sbf = new StringBuffer();
- int unit = 0;
- int before = -1;
- while (money != 0) {
- int number = money % 10;
- if(number == 0 && before != 0) {
- sbf.insert(0, data[number]);
- before = 0;
- } else if(number == 0 && before == 0) {
- before = 0;
- } else {
- sbf.insert(0, units[unit++]);
- sbf.insert(0, data[number]);
- before = -1;
- }
- money /= 10;
- }
- return sbf.toString();
- }
- }