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;
        }
    }

    此刻,静下心来学习
  • 相关阅读:
    异常
    带参数的方法
    变量,基本类型,数据类型和运算符
    数据类型转换(针对数字类型)
    this关键字
    面向对象DAO模式
    常见类 Object
    方法和包
    final关键字
    abstract关键字
  • 原文地址:https://www.cnblogs.com/bandariFang/p/6925086.html
Copyright © 2011-2022 走看看