/** * @author lautturi.com * Java example: round double to 1 decimal place in java */ import java.util.*; public class Lautturi { public static double round(double value, int decimalPoints) { double d = Math.pow(10, decimalPoints); return Math.round(value * d) / d; } public static void main(String[] args) { double d = 3.141; d = round(d, 1); System.out.println(d); } }
output:
3.1