Here you can find the source of round(double a, int decimal)
public static final double round(double a, int decimal)
//package com.java2s; public class Main { public static final double round(double a, int decimal) { try {/* w ww. j av a 2 s . c om*/ String str = String.valueOf(a); int idx = str.indexOf("."); if (idx == -1 || idx == str.length() - 1) return Double.parseDouble(str); return Double.parseDouble(str.substring(0, Math.min(str.length(), idx + decimal + 1))); } catch (Exception e) { System.out.println("There is some error MathUtil.round: " + e.getMessage()); return 0; } } }