2013-11-26 3 views
1

예 : - 이중 ab = 1234567.00;android의 쉼표로 숫자 그룹화

예상 출력은 ab = 12,34,567입니다.

그러나 다음 형식은 기본 3 자리 그룹화를 제공합니다.

또한 함께 노력
DecimalFormat df_separator = new DecimalFormat("###,###,##0.00"); 

,

헛된 여전히
DecimalFormat df_separator = new DecimalFormat("###,##,##0.00"); 

이 .......

여기

답변

2

당신은 선생님이고,

NumberFormat numberFormat = NumberFormat.getInstance(); 
String formattedNr = numberFormat.format(12345678L); 

이 당신에게 줄 것이다 : 12,345,678.00

편집 :

public String formatDouble(double number) 
{ 
    String result = ""; 
    String numberStr = String.valueOf(number); 
    char[] charArray = numberStr.toCharArray(); 
    Character[] charObjectArray = ArrayUtils.toObject(charArray); 
    for (int i=charObjectArray.length()-1; i>=0 i++) 
    { 
     if (charObjectArray[i] == ".") 
     { 
      result = "." + result; 
      continue; 
     } 
     result = charObjectArray[i] + result; 
     if (i % 2 == 0) result = "," + result; 
    } 
    return result; 
} 

이것은 JVM atm이 없으므로 가상 코드이지만 (거의) 작업을 수행해야합니다.

편집 : 마지막

프로젝트에 다음 항아리를 추가 : http://icu-project.org/apiref/icu4j/com/ibm/icu/text/NumberFormat.html

Format format = com.ibm.icu.text.NumberFormat.getCurrencyInstance(new Locale("en", "in")); 
System.out.println(format.format(new BigDecimal("100000000"))); 
+0

나는 내 게시물을 업데이 트했습니다 – Manitoba

+0

이봐, 그게 아니야 .... 나는 인도 표준에 따라 그것을 원해. 1,23,45,678.00 – Exceptional

+0

업데이트 및 작동 – Manitoba

1
double ab=1234567.00; 
String str = new DecimalFormat("#,##,##,###.00").format(ab); 
Log.d("TAG", str); 

이 시도.

+0

이봐, 그게 아니야 .... 나는 인도 표준에 따라 원한다. 1,23,45,678.00 – Exceptional

+0

See 편집 된 답변 – Triode

관련 문제