<legend id='cn2EF'><style id='cn2EF'><dir id='cn2EF'><q id='cn2EF'></q></dir></style></legend>

    <small id='cn2EF'></small><noframes id='cn2EF'>

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

    1. <tfoot id='cn2EF'></tfoot>

      Java - 格式化数字以仅打印小数部分

      时间:2023-09-29
        <bdo id='Foivn'></bdo><ul id='Foivn'></ul>

          <tbody id='Foivn'></tbody>
        1. <tfoot id='Foivn'></tfoot>

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

                <small id='Foivn'></small><noframes id='Foivn'>

                <legend id='Foivn'><style id='Foivn'><dir id='Foivn'><q id='Foivn'></q></dir></style></legend>
                本文介绍了Java - 格式化数字以仅打印小数部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                Is there a simple way in Java to format a decimal, float, double, etc to ONLY print the decimal portion of the number? I do not need the integer portion, even/especially if it is zero! I am currently using the String.indexOf(".") method combined with the String.substring() method to pick off the portion of the number on the right side of the decimal. Is there a cleaner way to do this? Couldn't find anything in the DecimalFormat class or the printf method. Both always return a zero before the decimal place.

                解决方案

                You can remove the integer part of the value by casting the double to a long. You can then subtract this from the original value to be left with only the fractional value:

                double val = 3.5;
                long intPartVal= (long) val;
                double fracPartVal = val - intPartVal;
                System.out.println(fracPartVal);
                

                And if you want to get rid of the leading zero you can do this:

                System.out.println(("" + fracPartVal).substring(1));
                

                这篇关于Java - 格式化数字以仅打印小数部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Java:当秒和毫秒都为 0 时,DateTimeFormatter 无法解析 下一篇:将日期从 8 月 14 日格式化为 YYYYMMDD

                相关文章

                最新文章

                <tfoot id='DzHtd'></tfoot>
                  <bdo id='DzHtd'></bdo><ul id='DzHtd'></ul>

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

              • <small id='DzHtd'></small><noframes id='DzHtd'>