From the course: Java 8+ Essential Training: Syntax and Structure

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Format numeric values as strings

Format numeric values as strings - Java Tutorial

From the course: Java 8+ Essential Training: Syntax and Structure

Start my 1-month free trial

Format numeric values as strings

- [Narrator] I've previously described how to convert a numeric value into a string, using the primitive data types helper classes, but you can also use a set of formatter classes that are provided with the Java RunTime to present formatted numbers and currency values. In this project, my main method declares a double value. Notice, I'm using the underscore characters to make the value more readable, but this is a simple primitive value of one million, two hundred thirty four thousand, and some pennies. So now, I'm going to format this. I'll use a class named Number Format. It's a member of the Java.txt package. As with all classes that aren't members of Java.lang or other automatic packages, I have to import the class. Intelligidea makes that easy, I just select the class from the list and the required import statement is added at the top. I'll call this number format, and I'll get its reference using a static method of the number format class. There are many different methods you…

Contents