 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Precision Handling in Java
Let us see how precisions are handled in Java −
Example
import java.io.*; import java.lang.*; public class Demo{    public static void main(String[] args){       double my_val = 34.909;       System.out.println("The formatted value of 34.909 is ");       System.out.println(String.format("%.7f", my_val));       double my_val_2 = 12.56;       System.out.println("The formatted value of 12.56 is ");       System.out.println(String.format("%.9f", my_val_2));    } }  Output
The formatted value of 34.909 is 34.9090000 The formatted value of 12.56 is 12.560000000
A class named Demo contains the main function, where a double valued integer is declared, and it is formatted by specifying the number that it should be formatted to. Similarly, another double variable is defined, and formatted and printed on the screen.
Advertisements
 