import java.text.NumberFormat; public class RoundEx{ public String rounded(String str) { if (str != null) { if (str.equalsIgnoreCase("0.0") || str.equalsIgnoreCase("NaN") || str.equalsIgnoreCase("0") || str.equalsIgnoreCase("N/A")) return "."; if (!isNumber(str)){ // if not a number: mod on 27th,Mar,07 return str; }//if try { NumberFormat numberFormat = NumberFormat.getNumberInstance(); numberFormat.setMaximumFractionDigits(2); numberFormat.setGroupingUsed(false);//if it is true, we will get like 2,1345 return numberFormat.format(Double.parseDouble(str)); } catch (Exception e) { System.out.println("Numberformat error for the string value:" + str); e.printStackTrace(); }// catch }// if(str!=null return "--"; }// public String rounded(String.. public static boolean isNumber(String str) {//mod on 27th,Mar,07 str.trim(); if(str.equals(".")||str.equals("")||str.equals("-")||str.equals("-.")){//eg: "." or "" or "-." return false; }//if int dotCount=0; for(int i=0;i='0' && ch<='9'){ }else if(ch=='.' && dotCount<1){ dotCount++; }else if((ch=='-'||ch=='+')&&i==0){//minus/plus should be in first position }else{ return false; }//else }//for(int i=0;.. return true; }// public boolean isNumber(.. public static void main(String[] args) { RoundEx obj=new RoundEx(); String s="36542365.2365"; System.out.println(isNumber(s)); System.out.println("Rounded value "+obj.rounded(s)); }//main }// class