String.format("%.nf",d);----表示保留N位

  public static void main(String[] args) {
    double d = 3.1415926;
    String result1 = String.format("%.2f", d);
    String result = String.format("%.3f", d);
    System.out.println(result1);//3.14
    System.out.println(result);//3.142
  }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-11-19
  • 2021-10-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案