veronikaaa86

Decimal Format

Feb 3rd, 2018
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.37 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2.  
  3. public class Demo {
  4.     public static void main(String[] args) {
  5.  
  6.         DecimalFormat df = new DecimalFormat("#.###");
  7.  
  8.         double numberOne = 2.3265683;
  9.         double numberTwo = 12.000000;
  10.  
  11.         System.out.printf("%s%n", df.format(numberOne)); // 2.327
  12.         System.out.printf("%s", df.format(numberTwo)); // 12
  13.     }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment