Search code examples
javaandroidgalaxy-tabnumberformatexception

Android: weird galaxy tab behavior


In android phone this method works fine. It takes any double number and changes to two decimals after dot. But in galaxy tab, number changes to not 0.00, but 0,00. So, when I convert from String to double, I get exception. Why is it acting like that? screenshot


Solution

  • Its because of the locality of your tablet, with the locality set on the tablet the numerical seperator is ,, while on other localities (your phone for example) it is ..

    You can change the locality using this piece of code:

    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Local.GERMAN);
    otherSymbols.setDecimalSeparator(',');
    otherSymbols.setGroupingSeparator('.'); 
    DecimalFormat df = new DecimalFormat(formatString, otherSymbols);
    

    Current local can be gotten using Locale.LOCALITY which can be found in java.util.Local

    Here is a workaround for you if you prefer.
    Here is a very nice question with related answers (including the one I put here) for you.