15 Apr 2013

Number Formater using custom decimal points in Android.


Here is the post for set number format in values with any of decimal points and Group separator as well. 

public String setNumberFormat(Float numval)
       {            
              String numformateString=123,456,789.00;

              DecimalFormat fmt = new DecimalFormat();
              DecimalFormatSymbols fmts = new DecimalFormatSymbols();
              fmt.setGroupingUsed(true);

              if(numformateString.equalsIgnoreCase("123,456,789.00"))
              {
                     fmts.setGroupingSeparator(',');         
                     fmts.setDecimalSeparator('.');   

              }
              else if(numformateString.equalsIgnoreCase("123.456.789,00"))
              {
                     fmts.setGroupingSeparator('.');         
                     fmts.setDecimalSeparator(',');
                     fmts.setPerMill('.');                    

              }
              else if(numformateString.equalsIgnoreCase("123 456 789,00"))
              {
                     fmts.setGroupingSeparator(' ');         
                     fmts.setDecimalSeparator(',');
                     fmts.setPerMill(' ');
              }
              else
              {

                     fmts.setGroupingSeparator('\'');        
                     fmts.setDecimalSeparator(',');

              }
              fmt.setDecimalFormatSymbols(fmts);                    
              return fmt.format(numval);
       }


i will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.
Thank you :)

No comments:

Post a Comment