zoukankan      html  css  js  c++  java
  • 025_取余运算

    public without sharing class MathHelper {
        
        /*
            是否整除
            @param dividend 被除数
            @param divider  除数
            @return 整除返回true,不整除返回false
        */
        public static Boolean isDivisibility(Integer dividend,Integer divider) {
            //先将被除数转换成Decimal,否则先计算整数除法结果为Integer类型,然后将整数转换成Decimal
            Decimal resultDecimal = Decimal.valueOf(dividend) / divider;
            //获取结果上线
            Integer resultSeiling = Integer.valueOf(resultDecimal.round(System.RoundingMode.CEILING));
            Integer resultDown = Integer.valueOf(resultDecimal.round(System.RoundingMode.DOWN));
            
            return resultSeiling == resultDown;
        }
        
        /*
            获取余数
            @param dividend 被除数
            @param divider  除数
            @return 返回余数
        */
        public static Integer getRemainder(Integer dividend,Integer divider) {
            Decimal resultDecimal = Decimal.valueOf(dividend) / divider;
            Integer resultDown = Integer.valueOf(resultDecimal.round(System.RoundingMode.DOWN));
            return dividend - resultDown * divider;
        }
    }

    此刻,静下心来学习
  • 相关阅读:
    C++ 纸牌 今日头条面试题
    c++ 病句 今日头条面试题
    C++ 球迷 今日头条面试题
    C++ 活动安排
    C++ 弗洛伊德算法
    填坑 bzoj3337
    bzoj3884 上帝与集合的正确用法
    人参中第一次膜你退货
    洛谷P2216 [HAOI2007]理想的正方形
    洛谷 P1099 树网的核+P2491 [SDOI2011]消防
  • 原文地址:https://www.cnblogs.com/bandariFang/p/6925086.html
Copyright © 2011-2022 走看看