posts - 14,  comments - 37,  trackbacks - 0

1.(double) (Math.round(sd3*10000)/10000.0); 

这样为保持4位

(double) (Math.round(sd3*100)/100.0);

这样为保持2位.

 

2.另一种办法

import java.text.DecimalFormat;

DecimalFormat df2  = new DecimalFormat("###.00");

DecimalFormat df2  = new DecimalFormat("###.000");

System.out.println(df2.format(doube_var));

第一个为2位,第二个为3位.

posted on 2007-07-09 15:48 冰封的爱 阅读(11243) 评论(1)  编辑  收藏 所属分类: 常用工具

FeedBack:
# re: JAVA除法保留小数点后两位的两种方法
2008-01-30 17:38 | 怎么羡慕天空的飞鸟
谢谢了!  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(3)

随笔档案

文章分类

文章档案

相册

搜索

  •  

最新评论

阅读排行榜

评论排行榜