<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    成功捷徑,貴在堅持
    人為善,福雖未至禍已遠離; 人為惡,禍雖未至福已遠離
    文章出自http://www.cujava.com
    import java.math.BigDecimal;
    import java.text.DecimalFormat;

    public class TestGetInt{
    ? public static void main(String[] args){
    ? ? double i=2, j=2.1, k=2.5, m=2.9;
    ? ? System.out.println("舍掉小數取整:Math.floor(2)=" + (int)Math.floor(i));
    ? ? System.out.println("舍掉小數取整:Math.floor(2.1)=" + (int)Math.floor(j));
    ? ? System.out.println("舍掉小數取整:Math.floor(2.5)=" + (int)Math.floor(k));
    ? ? System.out.println("舍掉小數取整:Math.floor(2.9)=" + (int)Math.floor(m));
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
    ? ? /* 這段被注釋的代碼不能正確的實現四舍五入取整
    ? ? System.out.println("四舍五入取整:Math.rint(2)=" + (int)Math.rint(i));
    ? ? System.out.println("四舍五入取整:Math.rint(2.1)=" + (int)Math.rint(j));
    ? ? System.out.println("四舍五入取整:Math.rint(2.5)=" + (int)Math.rint(k));
    ? ? System.out.println("四舍五入取整:Math.rint(2.9)=" + (int)Math.rint(m));
    ? ?
    ? ? System.out.println("四舍五入取整:(2)=" + new DecimalFormat("0").format(i));
    ? ? System.out.println("四舍五入取整:(2.1)=" + new DecimalFormat("0").format(i));
    ? ? System.out.println("四舍五入取整:(2.5)=" + new DecimalFormat("0").format(i));
    ? ? System.out.println("四舍五入取整:(2.9)=" + new DecimalFormat("0").format(i));
    ? ? */
    ? ?
    ? ? System.out.println("四舍五入取整:(2)=" + new BigDecimal("2").setScale(0, BigDecimal.ROUND_HALF_UP));
    ? ? System.out.println("四舍五入取整:(2.1)=" + new BigDecimal("2.1").setScale(0, BigDecimal.ROUND_HALF_UP));
    ? ? System.out.println("四舍五入取整:(2.5)=" + new BigDecimal("2.5").setScale(0, BigDecimal.ROUND_HALF_UP));
    ? ? System.out.println("四舍五入取整:(2.9)=" + new BigDecimal("2.9").setScale(0, BigDecimal.ROUND_HALF_UP));

    ? ? System.out.println("湊整:Math.ceil(2)=" + (int)Math.ceil(i));
    ? ? System.out.println("湊整:Math.ceil(2.1)=" + (int)Math.ceil(j));
    ? ? System.out.println("湊整:Math.ceil(2.5)=" + (int)Math.ceil(k));
    ? ? System.out.println("湊整:Math.ceil(2.9)=" + (int)Math.ceil(m));

    ? ? System.out.println("舍掉小數取整:Math.floor(-2)=" + (int)Math.floor(-i));
    ? ? System.out.println("舍掉小數取整:Math.floor(-2.1)=" + (int)Math.floor(-j));
    ? ? System.out.println("舍掉小數取整:Math.floor(-2.5)=" + (int)Math.floor(-k));
    ? ? System.out.println("舍掉小數取整:Math.floor(-2.9)=" + (int)Math.floor(-m));
    ? ?
    ? ? System.out.println("四舍五入取整:(-2)=" + new BigDecimal("-2").setScale(0, BigDecimal.ROUND_HALF_UP));
    ? ? System.out.println("四舍五入取整:(-2.1)=" + new BigDecimal("-2.1").setScale(0, BigDecimal.ROUND_HALF_UP));
    ? ? System.out.println("四舍五入取整:(-2.5)=" + new BigDecimal("-2.5").setScale(0, BigDecimal.ROUND_HALF_UP));
    ? ? System.out.println("四舍五入取整:(-2.9)=" + new BigDecimal("-2.9").setScale(0, BigDecimal.ROUND_HALF_UP));

    ? ? System.out.println("湊整:Math.ceil(-2)=" + (int)Math.ceil(-i));
    ? ? System.out.println("湊整:Math.ceil(-2.1)=" + (int)Math.ceil(-j));
    ? ? System.out.println("湊整:Math.ceil(-2.5)=" + (int)Math.ceil(-k));
    ? ? System.out.println("湊整:Math.ceil(-2.9)=" + (int)Math.ceil(-m));
    ? ? }
    }
    posted on 2008-06-24 20:20 選寶網an9 閱讀(14920) 評論(1)  編輯  收藏 所屬分類: 轉載

    FeedBack:
    # 34800四舍五入到萬位
    2008-10-04 14:44 | 666
    34800四舍五入到萬位  回復  更多評論
      
    主站蜘蛛池模板: 欧洲美女大片免费播放器视频| 亚洲国产成人久久精品动漫| 亚洲第一成年人网站| 成人免费网站视频www| 青青久在线视频免费观看| 亚洲宅男永久在线| a级片免费在线播放| 亚洲精品第一国产综合精品99| 亚洲国产精品精华液| 久久久久久国产精品免费免费| 亚洲美女一区二区三区| 无码av免费网站| 国产亚洲人成网站在线观看不卡| 自拍日韩亚洲一区在线| 久久精品视频免费| 四虎1515hm免费国产| 国产高清免费观看| 亚洲色图激情文学| 女人18毛片水真多免费播放| 性色av极品无码专区亚洲| 亚洲成人影院在线观看| 中国一级毛片视频免费看| 久久亚洲AV成人无码软件| 在线精品免费视频无码的| 全黄A免费一级毛片| 亚洲av永久无码精品秋霞电影影院| 91精品国产免费网站| 亚洲日韩精品国产一区二区三区 | 在线电影你懂的亚洲| 中文字幕人成无码免费视频| 亚洲AV无码专区亚洲AV桃| 亚洲日韩精品无码专区网址| 91免费国产精品| 亚洲AV永久无码精品放毛片| 亚洲精品无码久久久久去q| 国产香蕉免费精品视频| 羞羞视频免费网站日本| 久久av无码专区亚洲av桃花岛| 夫妻免费无码V看片| a级毛片高清免费视频| 伊人久久五月丁香综合中文亚洲|