From the course: Java 11+ Essential Training

Unlock the full course today

Join today to access over 22,500 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 11+ Essential Training

Start my 1-month free trial

Format numeric values as strings

- [Instructor] I've previously described how to convert a numeric value to a string, using the primitive data types helper or wrapper classes. But you can also use a set of formatter classes to format numbers and currency values. You start by creating instances of these classes. I'll create one that I'll call numf, and I'll get that object using this expression, NumberFormat.getNumberInstance. There are a number of different methods that return instances of various objects. Now notice, when I reference the number format class, that there's an import statement that's being generated automatically by intelliJ IDEA. I'll talk more about imports later on, but what's important to know now, is that there's a certain set of classes in Java, such as the string class and those wrapper classes, that don't have to be explicitly imported, they're always available to the compiler. All other classes have to be imported. An import…

Contents