日志文章

2007年08月30日 17:54:08

java 基本数据类型

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 );
}

Tags: JAVA  

类别: Java |  评论(0) |  浏览(680) |  收藏
发表评论
看不清楚,换一张