Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2.  
  3. public class DecimalFormatExample {
  4.  
  5.     public static void main(String[] args) {
  6.    
  7.         double number = 123.456;
  8.        
  9.         //15 digits after decimal point
  10.         DecimalFormat decimalFormat = new DecimalFormat(".000000000000000");
  11.         System.out.println(decimalFormat.format(number));
  12.        
  13.         //15 digits before and after decimal point
  14.         DecimalFormat decimalFormat2 = new DecimalFormat("000000000000000.000000000000000");
  15.         System.out.println(decimalFormat2.format(number));
  16.        
  17.         //15 digits after decimal point
  18.         System.out.printf("%.15f", number);
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement