言語セットで小数点のコンマまたは小数点が使用されている場合、読み返す簡単な方法はありますか?
12762 次
5 に答える
31
編集:@Algarの提案に基づいて更新します。直接使用できます:
char separatorChar = DecimalFormatSymbols.getInstance().getDecimalSeparator();
常にのインスタンスを返すためDecimalFormatSymbols
。
NumberFormat nf = NumberFormat.getInstance();
if (nf instanceof DecimalFormat) {
DecimalFormatSymbols sym = ((DecimalFormat) nf).getDecimalFormatSymbols();
char decSeparator = sym.getDecimalSeparator();
}
ドキュメント:
NumberFormat
、、DecimalFormat
_DecimalFormatSymbols
DecimalFormatのドキュメントによると、NumberFormat.getInstance()を呼び出すことは安全ですが、DecimalFormat以外のサブクラスを返す可能性があります(私が見る他のオプションはChoiceFormatです)。ほとんどの場合、DecimalFormatである必要があります。その後、 aと比較decSeparator
して、使用しているフォーマットを確認できます。,
.
于 2011-11-18T19:51:36.437 に答える
2
私はこれを試しました、そしてそれはうまくいきました...
String osVersion = System.getProperty("os.version");
String PhoneModel = android.os.Build.MODEL;
String locale = this.getResources().getConfiguration().locale.getDisplayCountry();
char decSeparator = '*';
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
decSeparator = dfs.getDecimalSeparator();
String androidVersion = android.os.Build.VERSION.RELEASE;
String prologue = String.format("OS verson = %s PhoneModel = %s locale = %s DecimalFormatSymbol = [%c] androidVersion = %s ",
osVersion ,PhoneModel, locale, decSeparator,androidVersion);
于 2011-12-23T11:59:38.640 に答える
-1
簡単な方法があるかどうかはわかりませんが、どの言語セットが使用されているかをテストし、その言語でコンマまたは小数点が使用されているかどうかに応じて適切な変更を加えることができます。
于 2011-11-18T19:45:25.513 に答える