Created
January 7, 2018 21:38
-
-
Save zeeshanaslam78/6e471ff42ffd4d7542555bbde3daf99b to your computer and use it in GitHub Desktop.
Show two digits after decimal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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