java求百分比

来源:互联网 发布:mr在lte网络优化 编辑:程序博客网 时间:2024/05/01 03:07


int clickCount=16;

int showCount =18;


// 创建一个数值格式化对象  

NumberFormat numberFormat = NumberFormat.getInstance();  


// 设置精确到小数点后2位  

numberFormat.setMaximumFractionDigits(2); 


String result = numberFormat.format((float) clickCount / (float) showCount * 100);  


System.out.println("clickCount和showCount的百分比为:" + result + "%");  


0 0
原创粉丝点击