JAVA/소스코드
자바로 아라비아 숫자를 단위 변경하는 프로그램
nineDeveloper
2014. 9. 16. 18:36
728x90
반응형
import java.text.DecimalFormat;
public class ExchangeFormat {
public static void main(String[] ar) {
double db = 154782600032546D;
DecimalFormat d = new DecimalFormat("#,####");
String[] unit = new String[]{"", "만","억","조"};
String[] str = d.format(db).split(",");
String result = "";
int cnt = 0;
for(int i=str.length;i>0;i--) {
if(Integer.parseInt(str[i-1]) != 0) {
result = String.valueOf(Integer.parseInt(str[i-1])) + unit[cnt] + result;
}
cnt++;
}
System.out.println(result + "원");
}
}
결과
154조7826억3만2346원
728x90
반응형