java Programming Glossary: decimalplaces
How to check if a double has at most n decimal places? http://stackoverflow.com/questions/264937/how-to-check-if-a-double-has-at-most-n-decimal-places this method static boolean checkDecimalPlaces double d int decimalPlaces if d 0 return true double multiplier Math.pow 10 decimalPlaces.. if d 0 return true double multiplier Math.pow 10 decimalPlaces double check d multiplier check Math.round check check check.. private static boolean checkDecimalPlaces double d int decimalPlaces if d 0 return true final double epsilon Math.pow 10.0 decimalPlaces..
How do I format a number in java? http://stackoverflow.com/questions/50532/how-do-i-format-a-number-in-java this double r 5.1234 System.out.println r r is 5.1234 int decimalPlaces 2 BigDecimal bd new BigDecimal r setScale is immutable bd bd.setScale.. bd new BigDecimal r setScale is immutable bd bd.setScale decimalPlaces BigDecimal.ROUND_HALF_UP r bd.doubleValue System.out.println..
|