java round to 1 decimal place

www.‮l‬autturi.com
java round to 1 decimal place
/**
 * @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
Created Time:2017-10-01 15:53:33  Author:lautturi