I assume 123455 is a String .
String s = 123455; String s1 = s.substring( 0 , 1 ); // s1 = 1 String s2 = s.substring( 1 , 3 ); // s2 = 23 String s3 = s.substring( 2 , 7 ); // s3 = 455 s1 = s1 + ','; s2 = s2 + ','; s = s1 + s2; // s is a String equivalent to 1,23,455
Now we use the static int parseInt(String str) method to convert String to integer. This method returns the integer equivalent of the number contained in the String specified by str , using radix 10.
Here you cannot convert s ---> int . Since int has no commas. If you try to convert, you will get the following java.lang.NumberFormatException
You must use the DecimalFormat Class. http://download.oracle.com/javase/1.4.2/docs/api/java/text/DecimalFormat.html
Suhail gupta
source share