2014-02-18 9 views
0

내가 코드 블록을달러 통화로 especific 통화에서의 NumberFormat를 변경하는 방법

이중 가격 = rs.getDouble ("가격");

NumberFormat nf = NumberFormat.getCurrencyInstance();

문자열 formatedPrice = nf.format (price);

buff.append ("("+ "formatedPrice +") ");

코드를 실행하면 모든 것이 올바르게 작동하지만 통화는 예 : (C800)으로 설정됩니다. 나는 내 나라가 통화를 위해 콜론을 가지고 있기 때문에 그런 것 같지만, 그것은 우리가 지금 달러 통화를 사용하고있는 과거의 것입니다. 어떻게하면이 (C300) 대신 ($ 400)이 통화를 표시 할 수 있습니까? 어떤 도움을 주셔서 대단히 감사합니다.

NumberFormat nf= NumberFormat.getCurrencyInstance(Locale.US); 

답변

3

사용을 사용할 수있는 미국 달러를 사용하는 당신은 getCurrencyInstance에 매개 변수로 로케일을 추가 할 수 있습니다

NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US); 
+0

작품 매력 덕분에 같은 솔루션 솔루션 여기

double price = rs.getDouble("price"); NumberFormat nf= NumberFormat.getCurrencyInstance(); nf.setMaximumFractionDigits(2); Currency currency = Currency.getInstance(Locale.US); nf.setCurrency(currency); String formatedPrice = nf.format(price); System.out.println("(" + formatedPrice + ")"); 

입니다 귀하의 답변에 모두. 나는 멍청이이기 때문에 모두에게 점수를 줄 수는 없다. – Photomancia

+0

그러나 대답을 받아 들여야합니다 –

+2

@Photomancia 질문을 표기하기 위해 받아 들인 대답으로 받아 들여야합니다 –

1

는 대신 NumberFormat.getCurrencyInstance(Locale.US)

0

당신은 DecimalFormat를 사용할 수 있습니다 :

import java.text.DecimalFormat; 

public class Example { 
    public static void main(String[] args) { 
     double price = 1.99; 
     DecimalFormat decimalFormat = new DecimalFormat("$0.00"); 
     System.out.println(decimalFormat.format(price)); 
    } 
} 

이 제공 : $1,99

1

을 가정

0

당신은 여기 $

에 기본 수있는 것은