From the course: Java 8 Essential Training

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Formatting numeric values as strings

Formatting numeric values as strings - Java Tutorial

From the course: Java 8 Essential Training

Formatting numeric values as strings

- I've previously described how to start with a string containing numeric characters and convert that to a primitive value using the primitive data type helper classes and their parse methods. For example, a string of one, two, three, four could be turned into a double value using the double classes parse double method. But you can also go from a primitive value to a formatted string using a variety of classes provided in the Java runtime. In this project, FormatNumbers, I've declared a single primitive value named doubleValue. It has a value in the millions. The underscores are only there for readability and are ignored by the compiler. I'm going to take that value and present a formatted string. As I did previously, I'll use the NumberFormat class. I'll type the beginning of the class name and select it and an import statement is added for me. I'll give this a name of numf for NumberFormat. And I'll get its reference by…

Contents