Skip to content

Instantly share code, notes, and snippets.

@zeeshanaslam78
Created January 7, 2018 21:38
Show Gist options
  • Save zeeshanaslam78/6e471ff42ffd4d7542555bbde3daf99b to your computer and use it in GitHub Desktop.
Save zeeshanaslam78/6e471ff42ffd4d7542555bbde3daf99b to your computer and use it in GitHub Desktop.
Show two digits after decimal
One Way
double number = 81.53104456348756;
System.out.println("Output: " + new DecimalFormat("##.##").format(number));
Output: 81.53
Other Way
double oldNumber = 55.654322;
double newNumber = (int)Math.round(oldNumber * 100)/(double)100;
System.out.println("Output: " + newNumber);
Output: 55.65
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment