Converting int to String using StringBuffer or StringBuilder You can specify the number of decimal places and comma separator for better readability as shown in the above example. If you know how to use DecimalFormat method, it is the best option for converting Integer to String, because of the level of control that you can have with the formatting. Output The number to be converted is: 12345 ("The string version of 12345 is: " + str) ("The number to be converted is: " + number) import ĭecimalFormat numberFormat = new DecimalFormat("#,#") You can use it to format a number to a String representation following a certain pattern. It has a lot of features designed to parse and format numbers. Output With format method: string = -1234 Converting int to String using DecimalFormatĭecimalFormat is a concrete subclass of NumberFormat class that formats decimal numbers. String str = String.format("%d", number) This method returns a formatted string, according to the format specifier and the specified arguments.Ĭonvert int to String using String.format().
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |