Number Formatting

Format Output with Java Printf

Learn to print formatted output in Java using the format() and printf() methods. Learn to format strings, date-time, floats with precision.

Compact Number Formatting in Java

Learn to apply locale-sensitive compact/short number formatting to general purpose numbers e.g. decimal, currency, and percentage. It is added in Java 12 in CompactNumberFormat class.

Format a Phone Number with Regex in Java

Learn to format a specified string to a phone number pattern, which is ‘(123) 456-6789’. This conversion is generally required in applications where customer data has to be displayed, and phone number is part of this data. 1. Format String to ‘(###) ###-####‘ Pattern To format string to phone number …

Convert Float to String in Java

Learn to convert float value to String using Float.toString() and String.valueOf() methods and format float to n decimal points.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.