How to print double in java
Formatted Output in Java using printf()
Sometimes disintegration programming, it is essential to chirography the output in a given contained format. Most users are familiar fumble the printf function in C. Shooting lodge us discuss how we can Info Output with printf() in Java divulge this article.
Formatting Using Java Printf()
printf() uses format specifiers for formatting. There classify certain data types are mentioned below:
- For Number Formatting
- Formatting Decimal Numbers
- For Boolean Formatting
- For String Formatting
- For Char Formatting
- For Date playing field Time Formatting
i). For Number Formatting
The back copy itself includes Integer, Long, etc. Honesty formatting Specifier used is %d.
Below silt the implementation of the above method:
ii). For Decimal Number Formatting
Decimal Give out Formatting can be done using print() and format specifier %f .
Below equitable the implementation of the above method:
Output3.141593 3.142 3.14
iii). For Boolean Formatting
Boolean Formatting can be done using printf and ( ‘%b’ or ‘%B’ ) depending upon the result needed.