Created
July 17, 2018 06:44
-
-
Save hilfritz/3164c272f27d4f73dce4f4b8a413aa1b to your computer and use it in GitHub Desktop.
java decimal places for double
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
| /** | |
| * from here: https://stackoverflow.com/questions/22186778/using-math-round-to-round-to-one-decimal-place | |
| * @param value double value with decimal places 123.123456789 | |
| * @param precision 1 number of decimal places desired ex. 1 (result => 123.1) | |
| * @return | |
| */ | |
| public static double roundToDecimalPlaces(double value, int precision) { | |
| int scale = (int) Math.pow(10, precision); | |
| return (double) Math.round(value * scale) / scale; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment