Formatting the floating point values

suggest change

Floating point Numbers can be formatted as a decimal number using String.format with 'f' flag

//Two digits in fracttional part are rounded
String format1 = String.format("%.2f", 1.2399);
System.out.println(format1); // "1.24"

// three digits in fractional part are rounded 
String format2 = String.format("%.3f", 1.2399);
System.out.println(format2); // "1.240"

//rounded to two digits, filled with zero 
String format3 = String.format("%.2f", 1.2);
System.out.println(format3); // returns "1.20"

//rounder to two digits
String format4 = String.format("%.2f", 3.19999);
System.out.println(format4); // "3.20"

Floating point Numbers can be formatted as a decimal number using DecimalFormat

// rounded with one digit fractional part 
 String format = new DecimalFormat("0.#").format(4.3200);
 System.out.println(format); // 4.3
 
// rounded with two digit fractional part 
 String format = new DecimalFormat("0.##").format(1.2323000);
 System.out.println(format); //1.23

 // formatting floating numbers to decimal number
 double dv = 123456789;
 System.out.println(dv); // 1.23456789E8
 String format =  new DecimalFormat("0").format(dv);
 System.out.println(format); //123456789

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Floating Point Operations:
* Formatting the floating point values

Table Of Contents
8 Arrays
10 Maps
11 Strings
25 JAXB
29 Enums
32 Audio
41 Scanner
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
127 Floating Point Operations
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap