📄 e314. formatting and parsing locale-specific currency.txt
字号:
// Format
Locale locale = Locale.GERMANY;
String string = NumberFormat.getCurrencyInstance(locale).format(123.45);
// 123,45 DM
locale = Locale.CANADA;
string = NumberFormat.getCurrencyInstance(locale).format(123.45);
// $123.45
// Parse
try {
Number number = NumberFormat.getCurrencyInstance(locale).parse("$123.45");
// 123.45
if (number instanceof Long) {
// Long value
} else {
// Double value
}
} catch (ParseException e) {
}
Related Examples
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -