Write code to round a double value by precision
//package com.book2s; public class Main { public static void main(String[] argv) { double value = 42.45678; int precision = 2; System.out.println(round(value, precision)); }// www . j a v a2 s. c o m public static double round(double value, int precision) { if (precision > 0) { double exp = Math.pow(10, precision); return Math.round(value * exp) / exp; } else { return Math.round(value); } } }