Here you can find the source of round(double number)
Parameter | Description |
---|---|
number | the number to round |
private static String round(double number)
//package com.java2s; //License from project: Open Source License import java.math.RoundingMode; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Locale; public class Main { /**/* w ww . ja va2 s. co m*/ * Rounds the given number to two decimals. * * @param number the number to round * @return the rounded number */ private static String round(double number) { DecimalFormat df = new DecimalFormat("#.##"); df.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance(Locale.US)); df.setRoundingMode(RoundingMode.HALF_UP); return df.format(number); } }