Java 中 # 格式標記


將 # 標誌應用於 %o、%x、%e 和 %f 格式說明符。如果要使用 0x 字首顯示十六進位制數字,則使用 # 字首 %x 說明符。

使用 # 字首 %x 說明符後,十六進位制數字將使用 0x 字首列印。

讓我們看一個使用 $e 的示例。其中包含小數點,即使沒有小數位數,也是如此 -

示例

 即時演示

import java.util.Formatter;
public class Demo {
   public static void main(String args[]) {
      Formatter f = new Formatter();
      System.out.println(f.format("%#e", 5F));
   }
}

輸出

5.000000e+00

更新日期:2019 年 7 月 30 日

300 次瀏覽

開啟你的 職業

透過完成課程獲得認證

開始
廣告