类 MathUtil

java.lang.Object
com.weicoder.common.util.MathUtil
直接已知子类:
U.M

public class MathUtil extends Object
各种数学相关操作类
作者:
WD
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static BigDecimal
    add(Object... values)
    提供精确的加法运算。
    static byte[]
    bytes(Random r, int len, int s, int e)
    为大数据优化的方法
    static List<byte[]>
    bytes(Random r, int len, int s, int e, int n)
    为大数据优化的方法
    static BigDecimal
    divide(Object v1, Object v2)
    提供(相对)精确的除法运算,当发生除不尽的情况时,精确到 小数点以后2位,以后的数字四舍五入。
    static BigDecimal
    divide(Object v1, Object v2, int scale)
    提供(相对)精确的除法运算,当发生除不尽的情况时,精确到 小数点以后2位,以后的数字四舍五入。
    static BigDecimal
    multiply(Object... values)
    提供精确的乘法运算。
    static byte[]
    nextBytes(int len, int m, int n)
     
    static byte[]
    nextBytes(Random r, int len, int m, int n)
    获得
    static byte[]
    nextBytes(Random r, int len, int s, int e, boolean is)
    随机获得一个字节数组 确保输入的m和n在byte之内 不做额外验证
    static List<byte[]>
    nextBytes(Random r, int len, int s, int e, int n, boolean is)
    随机获得一个字节数组列表 验证s与e在Byte.min~Byte.max之间
    static double
    同方法Random.nextDouble()
    static float
    同方法Random.nextFloat()
    static int
    同方法Random.nextInt()
    static int
    nextInt(int n)
    同方法Random.nextInt(n)
    static int
    nextInt(int m, int n)
    在m-n的范围中随机获得
    static long
    同方法Random.nextLong()
    返回当前线程的ThreadLocalRandom
    static String
    random(int len)
    获取指定位数的随机数
    static BigDecimal
    提供(相对)精确的取模运算,当发生除不尽的情况时,精确到 小数点以后2位,以后的数字四舍五入。
    static BigDecimal
    remainder(Object v1, Object v2, int scale)
    提供(相对)精确的取模运算,当发生除不尽的情况时,精确到 小数点以后2位,以后的数字四舍五入。
    static BigDecimal
    提供精确的小数位四舍五入处理。
    static BigDecimal
    scale(Object v, int scale)
    提供精确的小数位四舍五入处理。
    static BigDecimal
    提供精确的减法运算。
    static BigDecimal
    subtract(Object v1, Object v2, int scale)
    提供精确的减法运算
    static String
    格式化数字 把数字里的,去掉
    static String
    根据传进来的值返回长数字字符串 去处科学计数法用

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

    • MathUtil

      public MathUtil()
  • 方法详细资料

    • random

      public static ThreadLocalRandom random()
      返回当前线程的ThreadLocalRandom
      返回:
      ThreadLocalRandom 独立线程的随机数
    • nextBytes

      public static byte[] nextBytes(int len, int m, int n)
    • nextBytes

      public static byte[] nextBytes(Random r, int len, int m, int n)
      获得
      参数:
      r -
      len -
      m -
      n -
      返回:
    • nextBytes

      public static byte[] nextBytes(Random r, int len, int s, int e, boolean is)
      随机获得一个字节数组 确保输入的m和n在byte之内 不做额外验证
      参数:
      r - 随机数生成类
      len - 生成长度
      m - 开始数
      n - 结束数
      is - 是否可重复 true 可重复 false 不可重复
      返回:
      字节数组
    • nextBytes

      public static List<byte[]> nextBytes(Random r, int len, int s, int e, int n, boolean is)
      随机获得一个字节数组列表 验证s与e在Byte.min~Byte.max之间
      参数:
      r - 随机数生成类
      len - 生成长度
      s - 开始数
      e - 结束数
      n - 生成列表长度
      is - 是否可重复 true 可重复 false 不可重复
      返回:
      字节数组
    • bytes

      public static List<byte[]> bytes(Random r, int len, int s, int e, int n)
      为大数据优化的方法
      参数:
      r - 随机数生成类
      len - 生成长度
      s - 开始数
      e - 结束数
      n - 生成列表长度
      返回:
      字节数组
    • bytes

      public static byte[] bytes(Random r, int len, int s, int e)
      为大数据优化的方法
      参数:
      r - 随机数生成类
      len - 生成长度
      m - 开始数
      n - 结束数
      返回:
      字节数组
    • nextInt

      public static int nextInt()
      同方法Random.nextInt()
      返回:
      int 返回的随机数
    • nextInt

      public static int nextInt(int n)
      同方法Random.nextInt(n)
      参数:
      n - 在0-n的范围中
      返回:
      int 返回的随机数
    • nextInt

      public static int nextInt(int m, int n)
      在m-n的范围中随机获得
      参数:
      m - 起始数
      n - 结束数
      返回:
      int 返回的随机数
    • nextDouble

      public static double nextDouble()
      同方法Random.nextDouble()
      返回:
      double 返回的随机数
    • nextFloat

      public static float nextFloat()
      同方法Random.nextFloat()
      返回:
      float 返回的随机数
    • nextLong

      public static long nextLong()
      同方法Random.nextLong()
      返回:
      long 返回的随机数
    • random

      public static String random(int len)
      获取指定位数的随机数
      参数:
      len - 随机长度
      返回:
      字符串格式的随机数
    • add

      public static BigDecimal add(Object... values)
      提供精确的加法运算。
      参数:
      values - 相加的数字
      返回:
      相加结果
    • subtract

      public static BigDecimal subtract(Object v1, Object v2)
      提供精确的减法运算。
      参数:
      v1 - 被减数
      v2 - 减数
      返回:
      结果
    • subtract

      public static BigDecimal subtract(Object v1, Object v2, int scale)
      提供精确的减法运算
      参数:
      v1 - 被减数
      v2 - 减数
      scale - 保留精度
      返回:
      结果
    • multiply

      public static BigDecimal multiply(Object... values)
      提供精确的乘法运算。
      参数:
      values - 相乘的数字
      返回:
      相乘结果
    • divide

      public static BigDecimal divide(Object v1, Object v2)
      提供(相对)精确的除法运算,当发生除不尽的情况时,精确到 小数点以后2位,以后的数字四舍五入。
      参数:
      v1 - 被除数
      v2 - 除数
      返回:
      两个参数的商
    • divide

      public static BigDecimal divide(Object v1, Object v2, int scale)
      提供(相对)精确的除法运算,当发生除不尽的情况时,精确到 小数点以后2位,以后的数字四舍五入。
      参数:
      v1 - 被除数
      v2 - 除数
      scale - 小数点后保留几位
      返回:
      两个参数的商
    • remainder

      public static BigDecimal remainder(Object v1, Object v2)
      提供(相对)精确的取模运算,当发生除不尽的情况时,精确到 小数点以后2位,以后的数字四舍五入。
      参数:
      v1 - 被除数
      v2 - 除数
      返回:
      两个参数的商
    • remainder

      public static BigDecimal remainder(Object v1, Object v2, int scale)
      提供(相对)精确的取模运算,当发生除不尽的情况时,精确到 小数点以后2位,以后的数字四舍五入。
      参数:
      v1 - 被除数
      v2 - 除数
      scale - 小数点后保留几位
      返回:
      两个参数的商
    • scale

      public static BigDecimal scale(Object v)
      提供精确的小数位四舍五入处理。
      参数:
      v - 需要四舍五入的数字
      返回:
      四舍五入后的结果
    • scale

      public static BigDecimal scale(Object v, int scale)
      提供精确的小数位四舍五入处理。
      参数:
      v - 需要四舍五入的数字
      scale - 小数点后保留几位
      返回:
      四舍五入后的结果
    • take

      public static String take(String v)
      格式化数字 把数字里的,去掉
      参数:
      v - 数字
      返回:
      去掉,后的数字
    • toString

      public static String toString(Object val)
      根据传进来的值返回长数字字符串 去处科学计数法用
      参数:
      val - 要获得的值
      返回:
      字符串