您的位置:首页 > 编程语言 > Java开发

java求百分比

2016-06-12 10:57 302 查看
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 + "%");  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: