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 冰封的爱 阅读(11265) 评论(1)  编辑  收藏 所属分类: 常用工具

FeedBack:
# re: JAVA除法保留小数点后两位的两种方法
2008-01-30 17:38 | 怎么羡慕天空的飞鸟
谢谢了!  回复  更多评论
  
<2025年6月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

常用链接

留言簿(3)

随笔档案

文章分类

文章档案

相册

搜索

  •  

最新评论

阅读排行榜

评论排行榜