5

NumberFormat の何かがわかりません。米国のロケールでは、コンマ (",") をグループ区切り記号として扱うと想定されています。

このロケールの不適切な場所にあるコンマが無視されるのはなぜですか?

NumberFormat format = DecimalFormat.getInstance(Locale.US); 
System.out.println(format.parse("5,500").longValue()); //5500
System.out.println(format.parse("550,0").longValue()); //5500
System.out.println(format.parse("5500,").longValue()); //5500

ロケールに従って String を Long に解析する他のアイデアはありますか (ロケールの間違った場所での「、」の入力は失敗するはずです)。

4

3 に答える 3

-1

As the comma is a the separator for thousands in US Locale, it is ignored when it is wrongly placed. All of these ouputs will print 5500.

于 2013-04-04T11:04:03.927 に答える