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

          聲明:

          該blog是為了收集資料,認識朋友,學習、提高技術,所以本blog的內容除非聲明,否則一律為轉載!!

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

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

          常用鏈接

          留言簿(3)

          隨筆分類(148)

          隨筆檔案(143)

          收藏夾(2)

          其他

          學習(技術)

          觀察思考(非技術)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

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

          public class Test_Double{
              
          public static void main(String[] args){
                  
          //-----方法1--------四舍五入  round對負數是五舍六入
                  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);//設定小數最大為數   ,那么顯示的最后會四舍五入的   
                  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
          主站蜘蛛池模板: 京山县| 三河市| 肇东市| 长汀县| 环江| 汾西县| 巴林右旗| 平和县| 交口县| 西吉县| 大荔县| 云安县| 章丘市| 昆山市| 桦川县| 泽库县| 巨野县| 金昌市| 贞丰县| 山阴县| 陆河县| 太白县| 万全县| 哈尔滨市| 凭祥市| 聂拉木县| 邢台县| 巴彦淖尔市| 沐川县| 合阳县| 大姚县| 吉隆县| 普洱| 陇西县| 普格县| 郧西县| 新昌县| 社会| 西宁市| 辉县市| 长兴县|