| | |
| | | * */ |
| | | public static Object divide(Object num,Object num2,Integer type){ |
| | | float res = 0; |
| | | if(num instanceof Integer) { |
| | | res = BigDecimal.valueOf((Integer)num).divide(BigDecimal.valueOf((Integer)num2), 2, RoundingMode.HALF_UP).floatValue(); |
| | | } |
| | | if(num instanceof Float) { |
| | | res = BigDecimal.valueOf((Float)num).divide(BigDecimal.valueOf((Float)num2), 2, RoundingMode.HALF_UP).floatValue(); |
| | | } |
| | | if(num instanceof Double) { |
| | | res = BigDecimal.valueOf((Double)num).divide(BigDecimal.valueOf((Double)num2), 2, RoundingMode.HALF_UP).floatValue(); |
| | | double num2Double=Double.parseDouble(num2.toString()); |
| | | if(num2Double!=0){ |
| | | |
| | | if (num instanceof Integer) { |
| | | res = BigDecimal.valueOf((Integer) num).divide(BigDecimal.valueOf((Integer) num2), 2, RoundingMode.HALF_UP).floatValue(); |
| | | } |
| | | if (num instanceof Float) { |
| | | res = BigDecimal.valueOf((Float) num).divide(BigDecimal.valueOf((Float) num2), 2, RoundingMode.HALF_UP).floatValue(); |
| | | } |
| | | if (num instanceof Double) { |
| | | res = BigDecimal.valueOf((Double) num).divide(BigDecimal.valueOf((Double) num2), 2, RoundingMode.HALF_UP).floatValue(); |
| | | } |
| | | } |
| | | //0.05 |
| | | if(type==1){ |
| | | if (type == 1) { |
| | | return res; |
| | | } |
| | | //5 |
| | | else if(type==2){ |
| | | return (int)(res*100); |
| | | else if (type == 2) { |
| | | return (int) (res * 100); |
| | | } |
| | | //5% |
| | | return (int)(res*100)+"%"; |
| | | return (int) (res * 100) + "%"; |
| | | } |
| | | |
| | | } |