久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <legend id='9RtTM'><style id='9RtTM'><dir id='9RtTM'><q id='9RtTM'></q></dir></style></legend>

      <bdo id='9RtTM'></bdo><ul id='9RtTM'></ul>

      1. <tfoot id='9RtTM'></tfoot>

        <small id='9RtTM'></small><noframes id='9RtTM'>

        <i id='9RtTM'><tr id='9RtTM'><dt id='9RtTM'><q id='9RtTM'><span id='9RtTM'><b id='9RtTM'><form id='9RtTM'><ins id='9RtTM'></ins><ul id='9RtTM'></ul><sub id='9RtTM'></sub></form><legend id='9RtTM'></legend><bdo id='9RtTM'><pre id='9RtTM'><center id='9RtTM'></center></pre></bdo></b><th id='9RtTM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='9RtTM'><tfoot id='9RtTM'></tfoot><dl id='9RtTM'><fieldset id='9RtTM'></fieldset></dl></div>
      2. 格式,Java 中雙精度和整數的 2 位小數和 0

        Format, 2 decimal places for double and 0 for integer in java(格式,Java 中雙精度和整數的 2 位小數和 0)
          <tbody id='9Zvp0'></tbody>
          <bdo id='9Zvp0'></bdo><ul id='9Zvp0'></ul>
            <tfoot id='9Zvp0'></tfoot>
            <legend id='9Zvp0'><style id='9Zvp0'><dir id='9Zvp0'><q id='9Zvp0'></q></dir></style></legend>
            <i id='9Zvp0'><tr id='9Zvp0'><dt id='9Zvp0'><q id='9Zvp0'><span id='9Zvp0'><b id='9Zvp0'><form id='9Zvp0'><ins id='9Zvp0'></ins><ul id='9Zvp0'></ul><sub id='9Zvp0'></sub></form><legend id='9Zvp0'></legend><bdo id='9Zvp0'><pre id='9Zvp0'><center id='9Zvp0'></center></pre></bdo></b><th id='9Zvp0'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='9Zvp0'><tfoot id='9Zvp0'></tfoot><dl id='9Zvp0'><fieldset id='9Zvp0'></fieldset></dl></div>

              <small id='9Zvp0'></small><noframes id='9Zvp0'>

                • 本文介紹了格式,Java 中雙精度和整數的 2 位小數和 0的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  如果它有分數,我正在嘗試將雙精度格式化為精確的 2 位小數,否則使用 DecimalFormat 將其截斷

                  I am trying to format a double to exact 2 decimal places if it has fraction, and cut it off otherwise using DecimalFormat

                  所以,我想實現下一個結果:

                  So, I'd like to achieve next results:

                  100.123 -> 100.12
                  100.12  -> 100.12
                  100.1   -> 100.10
                  100     -> 100
                  

                  變體 #1

                  DecimalFormat("#,##0.00")
                  
                  100.1 -> 100.10
                  but
                  100   -> 100.00
                  

                  變體 #2

                  DecimalFormat("#,##0.##")
                  
                  100   -> 100
                  but
                  100.1 -> 100.1
                  

                  有什么想法在我的情況下選擇什么模式?

                  Have any ideas what pattern to choose in my case?

                  推薦答案

                  我達到的唯一解決方案是使用這里提到的 if 語句:https://stackoverflow.com/a/39268176/6619441

                  The only solution i reached is to use if statement like was mentioned here: https://stackoverflow.com/a/39268176/6619441

                  public static boolean isInteger(BigDecimal bigDecimal) {
                      int intVal = bigDecimal.intValue();
                      return bigDecimal.compareTo(new BigDecimal(intVal)) == 0;
                  }
                  
                  public static String myFormat(BigDecimal bigDecimal) {
                      String formatPattern = isInteger(bigDecimal) ? "#,##0" : "#,##0.00";
                      return new DecimalFormat(formatPattern).format(bigDecimal);
                  }
                  

                  測試

                  myFormat(new BigDecimal("100"));   // 100
                  myFormat(new BigDecimal("100.1")); // 100.10
                  

                  如果有人知道更優雅的方式,請分享!

                  If someone knows more elegant way, please share it!

                  這篇關于格式,Java 中雙精度和整數的 2 位小數和 0的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)
                  • <small id='1lSBW'></small><noframes id='1lSBW'>

                  • <tfoot id='1lSBW'></tfoot>

                    <legend id='1lSBW'><style id='1lSBW'><dir id='1lSBW'><q id='1lSBW'></q></dir></style></legend>
                      <tbody id='1lSBW'></tbody>

                        • <bdo id='1lSBW'></bdo><ul id='1lSBW'></ul>
                          <i id='1lSBW'><tr id='1lSBW'><dt id='1lSBW'><q id='1lSBW'><span id='1lSBW'><b id='1lSBW'><form id='1lSBW'><ins id='1lSBW'></ins><ul id='1lSBW'></ul><sub id='1lSBW'></sub></form><legend id='1lSBW'></legend><bdo id='1lSBW'><pre id='1lSBW'><center id='1lSBW'></center></pre></bdo></b><th id='1lSBW'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='1lSBW'><tfoot id='1lSBW'></tfoot><dl id='1lSBW'><fieldset id='1lSBW'></fieldset></dl></div>

                            主站蜘蛛池模板: 久久精品一区二区三区四区 | 欧美国产精品一区二区三区 | 成人性生交大片免费看中文带字幕 | www.日本在线观看 | 91在线精品视频 | 日本一区二区三区四区 | 欧美一区二区三区的 | 一区二区三区欧美大片 | 亚洲高清免费视频 | 99精品视频免费观看 | 日韩一区中文字幕 | 亚洲免费精品 | 欧美性受xxx | 免费av一区二区三区 | 欧美日韩在线一区二区 | 在线国产一区二区 | 一区二区三区亚洲视频 | 欧美二区在线 | 国产一级片免费视频 | 视频在线观看一区 | 成人影视网址 | 干干干操操操 | 免费一区二区 | 亚洲精品国产第一综合99久久 | 91性高湖久久久久久久久_久久99 | 欧美日韩国产在线观看 | 久久久久国产精品一区 | 久久精品视频99 | 日本黄色片免费在线观看 | 91色啪| 成人免费精品视频 | 欧美嘿咻 | 亚欧午夜| 久久综合一区二区 | 亚洲九九 | 久久久精品视频一区二区三区 | 免费观看一级特黄欧美大片 | 91精品国产综合久久香蕉922 | 日中文字幕在线 | 激情网站| 综合网视频 |