|
JAVA入门教程: 第 三 章 运算符和表达式: http://fanqiang.chinaunix.net/a4/b5/20010416/150916.html
四舍五入保留小数后两位: http://www.blogjava.net/limq/archive/2005/09/21/13694.aspx public static Double getRoundedDouble( double unroundedValue ){ // Get the integer portion of the value double intPortion = Math.floor( unroundedValue ); // Get the unrounded decimal portion double unroundedDecimalPortion = ( unroundedValue - intPortion ); double roundedDecimalPortion = Math.round( unroundedDecimalPortion * 100 ); // Shift the decimal point back two places to the right roundedDecimalPortion = roundedDecimalPortion / 100; // Add the int portion and decimal portions back together double total = intPortion + roundedDecimalPortion; return new Double( total ); }
|
一共有 0 条评论