---
# System prepended metadata

title: NumberFormat 和 Locale
tags: [ocpjp]

---

# NumberFormat 和 Locale
```java=
public static void main(String[] args) {
    double d =15;
    Locale l = new Locale("en", "US"); //獲得某個國家或地區的具體格式
    NumberFormat formatter = NumberFormat.getCurrencyInstance(l);//貨幣的format
    //或是可以寫成 NumberFormat formatter = NumberFormat.getCurrencyInstance(Locale.US);
    System.out.println(formatter.format(d));
}
```
Console:
```Console=
$15.00
```

:::info
**Locale 獲得某個國家或地區的具體格式，像是Locale.US**

**NumberFormat.getNumberInstance(Locale l)** 
某個國家的數字格式化

**NumberFormat.getCurrencyInstance(Locale l)**
某個國家的貨幣格式化
:::

###### tags: `ocpjp`