`
jbeduhai
  • 浏览: 497234 次
  • 性别: Icon_minigender_1
  • 来自: 山东
社区版块
存档分类
最新评论

两个数的百分比

    博客分类:
  • java
 
阅读更多
public static void main(String[] args) {
  int num1 = 1;

  int num2 = 2;

  // 创建一个数值格式化对象
  NumberFormat numberFormat = NumberFormat.getInstance();

  // 设置精确到小数点后2位
  numberFormat.setMaximumFractionDigits(2);

  String result = numberFormat.format((float)num1/(float)num2*100);
  System.out.println("num1和num2的百分比为:" + result + "%");

  }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics