patrick patrick - 1 year ago 111
Android Question

Decimal point or decimal comma in Android

Is there an easy way to read back if the language set uses a decimal comma or a decimal point?

Answer Source

I believe I have a way. I've never USED this, mind you, but it should certainly get you close, if not there:

NumberFormat nf = NumberFormat.getInstance();
if(nf instanceof DecimalFormat) {
    DecimalFormatSymbols sym = (DecimalFormatSymbols) nf.getDecimalFormatSymbols();
    char decSeparator = sym.getDecimalSeparator();


NumberFormat, DecimalFormat, DecimalFormatSymbols

According to the DecimalFormat docs, apparently calling NumberFormat.getInstance() is safe, but may return a subclass other than DecimalFormat (the other option I see is ChoiceFormat). I believe for the majority of instances it should be a DecimalFormat, and then you can compare decSeparator against a , and . to see which format it is using.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download