// hàm đổi chuổi số thành tiền
public static String[] splitStringEvery(String s, int interval) {
int arrayLength = (int) Math.ceil(((s.length() / (double) interval)));
String[] result = new String[arrayLength];
int j = 0;
int lastIndex = result.length - 1;
for (int i = 0; i < lastIndex; i++) {
result[i] = s.substring(j, j + interval);
j += interval;
} //Add the last bit
result[lastIndex] = s.substring(j);
return result;
}
public static String XuLyChuoiThanhTien(String s){
String S[] = splitStringEvery(s, 1);
String chuoi = "" ;
for(int i = 0 ; i < S.length;i++){
if (S.length == 5 || S.length == 6 || S.length == 7 || S.length == 8 ){
if(S.length == 5) {
if(i==1){
chuoi += S[i]+"." ;
}else {
chuoi += S[i] ;
}
}
if(S.length == 6) {
if(i==2){
chuoi += S[i]+"." ;
}else {
chuoi += S[i] ;
}
}
if(S.length == 7) {
if(i==0 || i==3){
chuoi += S[i]+"." ;
}else {
chuoi += S[i] ;
}
}
if(S.length == 8) {
if(i==1 || i==4){
chuoi += S[i]+"." ;
}else {
chuoi += S[i] ;
}
}
}else {
chuoi += S[i] ;
}
}
return chuoi+" VNĐ" ;
}
No comments:
Post a Comment