当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
Java求两个数的百分比
发布时间:2010/8/30 15:42:51 来源:城市学习网 编辑:ziteng

  public static void main(String[] args) {
  int num1 = 3;
  int num2 = 4;
  // 创建一个数值格式化对象
  NumberFormat numberFormat = NumberFormat.getInstance();
  // 设置精确到小数点后2位
  numberFormat.setMaximumFractionDigits(2);
  String result = numberFormat.format((float)num1/(float)num2*100);
  System.out.println("num1和num2的百分比为:" + result + "%");
  }

广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved