返回列表 發帖

String.format() 方法

本帖最後由 tonyh 於 2016-11-12 17:23 編輯

利用 String 類別下的 format() 方法,傳回特定格式的字串,其用法與 printf() 類似。
  1. public class Ch134 {
  2.         public static void main(String[] args) {
  3.                 double d=3.1415926;
  4.                 String res=String.format("%.2f", d);
  5.                 System.out.println(res);
  6.         }
  7. }
複製代碼

返回列表