How can I format an int to contain a set amount of characters? If the set amount of characters is 6 and the int == 12345 then it should become 012345.

Byron Tymvios

int iValue = 12345;

java.text.DecimalFormat df = new java.text.DecimalFormat("00000");
String sResult = df.format(iValue);
System.out.println("Format: " + sResult);

This should now output 012345

For further documentation on formating numeric primitives have a look at the API documentation for java.text.DecimalFormat.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact