From the course: Java 8 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
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 calling a static method of the NumberFormat class…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Working with object data types6m 27s
-
Using the String class5m 5s
-
(Locked)
Converting primitive values to strings4m 15s
-
(Locked)
Building a string from multiple values8m 44s
-
(Locked)
Comparing string values5m 51s
-
(Locked)
Formatting numeric values as strings4m 41s
-
(Locked)
Parsing string values3m 13s
-
(Locked)
Working with dates and times8m 35s
-
(Locked)
Challenge: Creating a simple calculator application1m 28s
-
(Locked)
Solution: Creating a simple calculator application1m 19s
-
(Locked)
-
-
-
-
-
-
-
-