课程: Java 8+ Essential Training: Syntax and Structure

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

Format numeric values as strings

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…

内容