隨筆 - 154  文章 - 60  trackbacks - 0
          <2008年3月>
          2425262728291
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          聲明:

          該blog是為了收集資料,認(rèn)識朋友,學(xué)習(xí)、提高技術(shù),所以本blog的內(nèi)容除非聲明,否則一律為轉(zhuǎn)載!!

          感謝那些公開自己技術(shù)成果的高人們!!!

          支持開源,尊重他人的勞動!!

          常用鏈接

          留言簿(3)

          隨筆分類(148)

          隨筆檔案(143)

          收藏夾(2)

          其他

          學(xué)習(xí)(技術(shù))

          觀察思考(非技術(shù))

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          代碼:
          import java.text.DecimalFormat;
          import java.math.BigDecimal;

          public class Test_Double{
              
          public static void main(String[] args){
                  
          //-----方法1--------四舍五入  round對負(fù)數(shù)是五舍六入
                  double d_1 = 123.9;
                  System.out.println(
          "d_1 = "+Math.round(d_1));
                  
          //-------方法2------------------
                  DecimalFormat decfmt = new DecimalFormat("##0.00");   
                    System.out.println(decfmt.format(
          1.33482222));
                    
          //--------方法3--------------
                    double x = 1.33345;   
                  java.text.NumberFormat formate 
          = java.text.NumberFormat.getNumberInstance();   
                  formate.setMaximumFractionDigits(
          3);//設(shè)定小數(shù)最大為數(shù)   ,那么顯示的最后會四舍五入的   
                  String m = formate.format(x);   
                  System.out.println(m);  
                  
          //--------方法4--------------
                  BigDecimal bd = new BigDecimal(1.234543);   
                  bd 
          = bd.setScale(3,BigDecimal.ROUND_HALF_EVEN);   
                  
          double d = bd.doubleValue();   
                  System.out.println(d);
              }

          }
          posted on 2008-03-20 14:20 lk 閱讀(3593) 評論(0)  編輯  收藏 所屬分類: j2se
          主站蜘蛛池模板: 绥芬河市| 和静县| 阿尔山市| 香河县| 东莞市| 汝南县| 琼海市| 汕头市| 闵行区| 英吉沙县| 富民县| 义马市| 双鸭山市| 沙河市| 北流市| 缙云县| 江华| 吉安县| 托克逊县| 苏州市| 潮安县| 恭城| 四子王旗| 射阳县| 贺州市| 永川市| 乐至县| 石渠县| 泽普县| 桃园县| 革吉县| 陕西省| 靖远县| 石景山区| 铅山县| 含山县| 兴城市| 镇赉县| 兴义市| 海阳市| 芷江|