首页 > 编程语言 > 详细

java 对象转整数,两个整数相除转百分数

时间:2019-05-06 21:56:13      阅读:505      评论:0      收藏:0      [点我收藏+]

 

 

public class MathUtil {
    
    public static void main(String[] args) {
        System.out.println(toPercent(1,3));
    }
    
    //a/b转百分数字符串 (double)Math.round( a/(double)b*1000)/1000:保留3位小数四舍五入
    private static String toPercent(int a,int b) {
        return (double)Math.round( a/(double)b*1000)/10+"%";
    }
    
    //Object转整数(失败返回null)
    private Integer toInt(Object o) {
        if (o!=null && !"".equals(o.toString())) {
            try {
                int parseInt = Integer.parseInt(o.toString());
                return parseInt;
            } catch (NumberFormatException e) {
                e.printStackTrace();
                return null;
            }
        }
        return null;
    }
}

 

java 对象转整数,两个整数相除转百分数

原文:https://www.cnblogs.com/libin6505/p/10822189.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!