<small id='0JvxG'></small><noframes id='0JvxG'>

      <i id='0JvxG'><tr id='0JvxG'><dt id='0JvxG'><q id='0JvxG'><span id='0JvxG'><b id='0JvxG'><form id='0JvxG'><ins id='0JvxG'></ins><ul id='0JvxG'></ul><sub id='0JvxG'></sub></form><legend id='0JvxG'></legend><bdo id='0JvxG'><pre id='0JvxG'><center id='0JvxG'></center></pre></bdo></b><th id='0JvxG'></th></span></q></dt></tr></i><div id='0JvxG'><tfoot id='0JvxG'></tfoot><dl id='0JvxG'><fieldset id='0JvxG'></fieldset></dl></div>
    1. <tfoot id='0JvxG'></tfoot>
      • <bdo id='0JvxG'></bdo><ul id='0JvxG'></ul>

    2. <legend id='0JvxG'><style id='0JvxG'><dir id='0JvxG'><q id='0JvxG'></q></dir></style></legend>

    3. Java 对任意数字进行四舍五入

      Java Round up Any Number(Java 对任意数字进行四舍五入)
        <legend id='7iOc2'><style id='7iOc2'><dir id='7iOc2'><q id='7iOc2'></q></dir></style></legend>

            <tbody id='7iOc2'></tbody>

            <bdo id='7iOc2'></bdo><ul id='7iOc2'></ul>
            <i id='7iOc2'><tr id='7iOc2'><dt id='7iOc2'><q id='7iOc2'><span id='7iOc2'><b id='7iOc2'><form id='7iOc2'><ins id='7iOc2'></ins><ul id='7iOc2'></ul><sub id='7iOc2'></sub></form><legend id='7iOc2'></legend><bdo id='7iOc2'><pre id='7iOc2'><center id='7iOc2'></center></pre></bdo></b><th id='7iOc2'></th></span></q></dt></tr></i><div id='7iOc2'><tfoot id='7iOc2'></tfoot><dl id='7iOc2'><fieldset id='7iOc2'></fieldset></dl></div>

            <small id='7iOc2'></small><noframes id='7iOc2'>

                <tfoot id='7iOc2'></tfoot>

                本文介绍了Java 对任意数字进行四舍五入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                对于一个简单的问题,我似乎找不到我正在寻找的答案:如何将任何数字四舍五入到最接近的 int?

                I can't seem to find the answer I'm looking for regarding a simple question: how do I round up any number to the nearest int?

                例如,只要数字为 0.2、0.7、0.2222、0.4324、0.99999,我希望结果为 1.

                For example, whenever the number is 0.2, 0.7, 0.2222, 0.4324, 0.99999 I would want the outcome to be 1.

                目前为止

                int b = (int) Math.ceil(a / 100);
                

                不过,它似乎没有做这项工作.

                It doesn't seem to be doing the job, though.

                推荐答案

                Math.ceil() 是要调用的正确函数.我猜 a 是一个 int,它会让 a/100 执行整数运算.改用 Math.ceil(a/100.0).

                Math.ceil() is the correct function to call. I'm guessing a is an int, which would make a / 100 perform integer arithmetic. Try Math.ceil(a / 100.0) instead.

                int a = 142;
                System.out.println(a / 100);
                System.out.println(Math.ceil(a / 100));
                System.out.println(a / 100.0);
                System.out.println(Math.ceil(a / 100.0));
                System.out.println((int) Math.ceil(a / 100.0));
                

                输出:

                1
                1.0
                1.42
                2.0
                2
                

                参见 http://ideone.com/yhT0l

                这篇关于Java 对任意数字进行四舍五入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                    <tbody id='8GX0o'></tbody>

                    <small id='8GX0o'></small><noframes id='8GX0o'>

                    <tfoot id='8GX0o'></tfoot>

                      <i id='8GX0o'><tr id='8GX0o'><dt id='8GX0o'><q id='8GX0o'><span id='8GX0o'><b id='8GX0o'><form id='8GX0o'><ins id='8GX0o'></ins><ul id='8GX0o'></ul><sub id='8GX0o'></sub></form><legend id='8GX0o'></legend><bdo id='8GX0o'><pre id='8GX0o'><center id='8GX0o'></center></pre></bdo></b><th id='8GX0o'></th></span></q></dt></tr></i><div id='8GX0o'><tfoot id='8GX0o'></tfoot><dl id='8GX0o'><fieldset id='8GX0o'></fieldset></dl></div>

                        <legend id='8GX0o'><style id='8GX0o'><dir id='8GX0o'><q id='8GX0o'></q></dir></style></legend>
                        • <bdo id='8GX0o'></bdo><ul id='8GX0o'></ul>