This article is reproduced, the original address: http://blog.csdn.net/star_huang/article/details/7639267
Today you have an issue that requires you to keep a double of the decimal point for the data of type two. Centralized solution for online search, copy come on, spare
First Result_value is the double before processing
Get_double is used to save my processed double
//programme One:Get_double = (Double) (Math.Round (result_value*100)/100.0) //Scenario Two:DecimalFormat DF =NewDecimalFormat ("#.##"); Get_double=double.parsedouble (Df.format (Result_value));//Programme III:get_double = double.parsedouble (String.Format ("%.2f", Result_value));//Programme IV:BigDecimal BD =NewBigdecimalresult_value (); BigDecimal Bd2= Bd.setscale (2, BigDecimal. ROUND_HALF_UP); Get_double= Double.parsedouble (Bd2. ToString ());
PS: I solved the problem with the second solution.
Other
Public Static int Scale ) { double result = 0.0; if (null ! = value) {new BigDecimal (string.valueof (value)). Setscale (Scale, ROUNDINGMODE.HALF_UP). Doublevalue (); } return result;
}
This method allows you to set the number of digits that are retained after the decimal point.