程序包 org.anyline.util

类 NumberUtil

java.lang.Object
org.anyline.util.NumberUtil

public class NumberUtil extends Object
  • 构造器详细资料

    • NumberUtil

      public NumberUtil()
  • 方法详细资料

    • format

      public static String format(String src, String pattern)
      数据格式化
      参数:
      src - src
      pattern - 名称统配符或正则
      返回:
      String
    • format

      public static String format(Number src, String pattern)
      数字格式化
      参数:
      src - src
      pattern - 名称统配符或正则
      返回:
      String
    • upper

      public static String upper(long num)
      中文大写(简体)
      参数:
      num - num
      返回:
      String
    • max

      public static BigDecimal max(BigDecimal... nums)
      选取最大数
      参数:
      nums - nums
      返回:
      BigDecimal
    • min

      public static BigDecimal min(BigDecimal... nums)
      选取最小数
      参数:
      nums - nums
      返回:
      BigDecimal
    • max

      public static double max(double... nums)
      选取最大数
      参数:
      nums - nums
      返回:
      double
    • min

      public static double min(double... nums)
      选取最小数
      参数:
      nums - nums
      返回:
      double
    • max

      public static int max(int... nums)
      选取最大数
      参数:
      nums - nums
      返回:
      int
    • min

      public static int min(int... nums)
      选取最小数
      参数:
      nums - nums
      返回:
      int
    • max

      public static long max(long... nums)
      选取最大数
      参数:
      nums - nums
      返回:
      long
    • min

      public static long min(long... nums)
      选取最小数
      参数:
      nums - nums
      返回:
      long
    • max

      public static float max(float... nums)
      选取最大数
      参数:
      nums - nums
      返回:
      float
    • min

      public static float min(float... nums)
      选取最小数
      参数:
      nums - nums
      返回:
      float
    • max

      public static short max(short... nums)
      选取最大数
      参数:
      nums - nums
      返回:
      short
    • min

      public static short min(short... nums)
      选取最小数
      参数:
      nums - nums
      返回:
      short
    • random

      public static int random(int fr, int to)
    • random

      public static double random(double fr, double to)
    • random

      public static long random(long fr, long to)
    • random

      public static float random(float fr, float to)
    • random

      public static List<Integer> random(int fr, int to, int qty)
    • random

      public static List<Double> random(double fr, double to, int qty)
    • random

      public static List<Float> random(float fr, float to, int qty)
    • random

      public static List<Long> random(long fr, long to, int qty)
    • isInt

      public static boolean isInt(double src)
    • isInt

      public static boolean isInt(float src)
    • bin2dec

      public static int bin2dec(String number)
      二进制转十进制
      参数:
      number - number
      返回:
      int
    • dec2bin

      public static String dec2bin(int number)
      十进制转二进制
      参数:
      number - number
      返回:
      String
    • int2bytes

      public static byte[] int2bytes(int in, boolean big)
      整形转换成网络传输的字节流(字节数组)型数据
      参数:
      in - 一个整型数据
      big - 是否大端
      返回:
      4个字节的byte数组
    • short2bytes

      public static byte[] short2bytes(short in, boolean big)
    • long2bytes

      public static byte[] long2bytes(long in, boolean big)
      长整形转换成网络传输的字节流(字节数组)型数据
      参数:
      in - 一个长整型数据
      big - 是否大端
      返回:
      8个字节的byte数组
    • int2bytes

      public static byte[] int2bytes(BigInteger n)
      大数字转换字节流(字节数组)型数据
      参数:
      n - 十进制
      返回:
      bytes
    • byte2bigint

      public static BigInteger byte2bigint(byte[] bytes)
      换字节流(字节数组)型数据转大数字
      参数:
      bytes - bytes
      返回:
      BigInteger
    • hex2dec

      public static int hex2dec(String hex)
      16进制转10进制
      参数:
      hex - hex
      返回:
      int
    • hex2dec

      public static int hex2dec(String[] hex, int start, int len)
      截取hex中fr到to部分转成10进制
      参数:
      hex - hex数组
      start - 开始位置
      len - 长度
      返回:
      int
    • byte2hex

      public static String byte2hex(byte[] bytes, String split)
    • byte2hex

      public static String byte2hex(byte[] bytes, int len)
    • byte2hex

      public static String byte2hex(byte[] bytes, int len, String split)
    • byte2hex

      public static String byte2hex(byte[] bytes, int start, int len, String split)
    • byte2hex

      public static String byte2hex(byte[] bytes)
    • byte2hexs

      public static String[] byte2hexs(byte[] bytes)
    • byte2hex

      public static String byte2hex(byte b)
    • dec2hex

      public static String dec2hex(int number)
    • dec2hex

      public static String[] dec2hex(int[] numbers)
    • byte2string

      public static String byte2string(byte[] bytes, int start, int len, Charset charset)
      从byte数组中截取start开始len位转换成String 按charset编码格式
      参数:
      bytes - bytes
      start - 开始
      len - 长度
      charset - 编码
      返回:
      String
    • byte2string

      public static String byte2string(byte[] bytes, int start, int len)
    • byte2string

      public static String byte2string(byte[] bytes)
    • byte2string

      public static String byte2string(byte[] bytes, int start)
    • byte2string

      public static String byte2string(byte[] bytes, Charset charset)
    • hex2bytes

      public static byte[] hex2bytes(String hex)
    • hex2byte

      public static byte hex2byte(String hex)
    • dec2bcd

      public static byte[] dec2bcd(long num)
    • byte2bin

      public static String byte2bin(byte b)
      将byte转成二进制
      参数:
      b - byte
      返回:
      String
    • byte2decimal

      public static int byte2decimal(byte res)
    • byte2ascii

      public static String byte2ascii(byte b)
      ascii码
      参数:
      b - byte
      返回:
      String
    • byte2bcd

      public static String byte2bcd(byte bit)
    • bytes2bcd

      public static String bytes2bcd(byte[] bytes)
    • string2hex

      public static String string2hex(String origin, String charset)
      String转16进制
      中文abc123_# >e4b8ade696876162633132335f23
      参数:
      origin - 原文
      返回:
      hex
    • string2hex

      public static String string2hex(String origin)
    • hex2string

      public static String hex2string(String hex, String charset)
      16进制转String
      e4b8ade696876162633132335f23 > 中文abc123_#
      参数:
      hex - hex
      返回:
      String
    • hex2string

      public static String hex2string(String hex)
    • hex2array

      public static String[] hex2array(String hex)
      16进制string拆分
      0102 > ["01","02"]
      参数:
      hex - hex
      返回:
      strings
    • string2bytes

      public static byte[] string2bytes(String src, String charset)
    • string2bytes

      public static byte[] string2bytes(String src)
    • string2ascii

      public static String string2ascii(String str)
      数字字符串转ASCII码字符串
      参数:
      str - 字符串
      返回:
      ASCII字符串
    • ascii2string

      public static String ascii2string(String content)
      ASCII码字符串转数字字符串
      参数:
      content - ASCII字符串
      返回:
      字符串
    • compress

      public static String compress(String src, boolean integer)
      压缩最前位的0与小数最后的0
      参数:
      src - src
      integer - 是否压缩成整数 1|1.0
      返回:
      String
    • compress

      public static double compress(double src)
    • compress

      public static String compress(String src)
    • byte2points

      public static double[] byte2points(byte[] bytes)
      byte转double[], 可用于把数据库中的point(JDBC取出byte[])转成double[]
      参数:
      bytes - bytes
      返回:
      double[]
    • byte2double

      public static double byte2double(byte[] bytes, int start)
      byte数组转double, 默认Double占用8个字节(64位)
      参数:
      bytes - byte数组
      start - 开始位置
      返回:
      double
    • double2bytes

      public static byte[] double2bytes(double d)
    • double2Bytes

      public static Byte[] double2Bytes(double d)
    • byte2int

      public static int byte2int(byte[] bytes, int start, int length, boolean big)
      字节数组中解析整型数据
      参数:
      bytes - byte数组
      start - 开始位置
      length - 长度
      big - 是否Big Endian
      返回:
      int
    • byte2int

      public static int byte2int(byte[] bytes, int start, int length)
    • byte2int

      public static int byte2int(byte[] bytes, int start)
    • byte2int

      public static int byte2int(byte[] bytes, int start, boolean big)
    • byte2short

      public static short byte2short(byte[] bytes, int start, int length)
    • byte2short

      public static short byte2short(byte[] bytes, int start)
    • byte2short

      public static short byte2short(byte[] bytes, int start, boolean big)
    • avg

      public static BigDecimal avg(List<BigDecimal> list, int scale, int round)
      平均值
      参数:
      list - 集合
      scale - 小数位
      round - 舍入模式 参考BigDecimal静态常量 ROUND_UP = 0 舍入远离零的舍入模式 在丢弃非零部分之前始终增加数字(始终对非零舍弃部分前面的数字加 1) 如:2.36 转成 2.4
      ROUND_DOWN = 1 接近零的舍入模式 在丢弃某部分之前始终不增加数字(从不对舍弃部分前面的数字加1, 即截短). 如:2.36 转成 2.3
      ROUND_CEILING = 2 接近正无穷大的舍入模式 如果 BigDecimal 为正, 则舍入行为与 ROUND_UP 相同 如果为负, 则舍入行为与 ROUND_DOWN 相同 相当于是 ROUND_UP 和 ROUND_DOWN 的合集
      ROUND_FLOOR = 3 接近负无穷大的舍入模式 如果 BigDecimal 为正, 则舍入行为与 ROUND_DOWN 相同 如果为负, 则舍入行为与 ROUND_UP 相同 与ROUND_CEILING 正好相反
      ROUND_HALF_UP = 4 四舍五入
      ROUND_HALF_DOWN = 5 五舍六入
      ROUND_HALF_EVEN = 6 四舍六入 五留双(银行家舍入法)
      如果舍弃部分左边的数字为奇数, 则舍入行为与 ROUND_HALF_UP 相同(四舍五入)
      如果为偶数, 则舍入行为与 ROUND_HALF_DOWN 相同(五舍六入)
      如:1.15 转成 1.2, 因为5前面的1是奇数;1.25 转成 1.2, 因为5前面的2是偶数
      ROUND_UNNECESSARY=7 断言所请求的操作具有准确的结果,因此不需要舍入。如果在产生不精确结果的操作上指定了该舍入模式,则会抛出ArithmeticException异常
      返回:
      平均值
    • avga

      public static BigDecimal avga(List<BigDecimal> list, int scale, int round)
    • var

      public static BigDecimal var(List<BigDecimal> list, int scale, int round)
      抽样方差variance 抽样方差s^2=[(x1-x)^2+(x2-x)^2+......(xn-x)^2]/(n-1)(x为平均数)
      参数:
      list - 集合
      scale - 小数位
      round - 舍入模式 参考BigDecimal静态常量 ROUND_UP = 0 舍入远离零的舍入模式 在丢弃非零部分之前始终增加数字(始终对非零舍弃部分前面的数字加 1) 如:2.36 转成 2.4
      ROUND_DOWN = 1 接近零的舍入模式 在丢弃某部分之前始终不增加数字(从不对舍弃部分前面的数字加1, 即截短). 如:2.36 转成 2.3
      ROUND_CEILING = 2 接近正无穷大的舍入模式 如果 BigDecimal 为正, 则舍入行为与 ROUND_UP 相同 如果为负, 则舍入行为与 ROUND_DOWN 相同 相当于是 ROUND_UP 和 ROUND_DOWN 的合集
      ROUND_FLOOR = 3 接近负无穷大的舍入模式 如果 BigDecimal 为正, 则舍入行为与 ROUND_DOWN 相同 如果为负, 则舍入行为与 ROUND_UP 相同 与ROUND_CEILING 正好相反
      ROUND_HALF_UP = 4 四舍五入
      ROUND_HALF_DOWN = 5 五舍六入
      ROUND_HALF_EVEN = 6 四舍六入 五留双(银行家舍入法)
      如果舍弃部分左边的数字为奇数, 则舍入行为与 ROUND_HALF_UP 相同(四舍五入)
      如果为偶数, 则舍入行为与 ROUND_HALF_DOWN 相同(五舍六入)
      如:1.15 转成 1.2, 因为5前面的1是奇数;1.25 转成 1.2, 因为5前面的2是偶数
      ROUND_UNNECESSARY=7 断言所请求的操作具有准确的结果,因此不需要舍入。如果在产生不精确结果的操作上指定了该舍入模式,则会抛出ArithmeticException异常
      返回:
      方差
    • vara

      public static BigDecimal vara(List<BigDecimal> list, int scale, int round)
    • varp

      public static BigDecimal varp(List<BigDecimal> list, int scale, int round)
      总体方差variance 总体方差s^2=[(x1-x)^2+(x2-x)^2+......(xn-x)^2]/n(x为平均数)
      参数:
      list - 集合
      scale - 小数位
      round - 舍入模式 参考BigDecimal静态常量 ROUND_UP = 0 舍入远离零的舍入模式 在丢弃非零部分之前始终增加数字(始终对非零舍弃部分前面的数字加 1) 如:2.36 转成 2.4
      ROUND_DOWN = 1 接近零的舍入模式 在丢弃某部分之前始终不增加数字(从不对舍弃部分前面的数字加1, 即截短). 如:2.36 转成 2.3
      ROUND_CEILING = 2 接近正无穷大的舍入模式 如果 BigDecimal 为正, 则舍入行为与 ROUND_UP 相同 如果为负, 则舍入行为与 ROUND_DOWN 相同 相当于是 ROUND_UP 和 ROUND_DOWN 的合集
      ROUND_FLOOR = 3 接近负无穷大的舍入模式 如果 BigDecimal 为正, 则舍入行为与 ROUND_DOWN 相同 如果为负, 则舍入行为与 ROUND_UP 相同 与ROUND_CEILING 正好相反
      ROUND_HALF_UP = 4 四舍五入
      ROUND_HALF_DOWN = 5 五舍六入
      ROUND_HALF_EVEN = 6 四舍六入 五留双(银行家舍入法)
      如果舍弃部分左边的数字为奇数, 则舍入行为与 ROUND_HALF_UP 相同(四舍五入)
      如果为偶数, 则舍入行为与 ROUND_HALF_DOWN 相同(五舍六入)
      如:1.15 转成 1.2, 因为5前面的1是奇数;1.25 转成 1.2, 因为5前面的2是偶数
      ROUND_UNNECESSARY=7 断言所请求的操作具有准确的结果,因此不需要舍入。如果在产生不精确结果的操作上指定了该舍入模式,则会抛出ArithmeticException异常
      返回:
      方差
    • varpa

      public static BigDecimal varpa(List<BigDecimal> list, int scale, int round)
    • stdev

      public static BigDecimal stdev(List<BigDecimal> list, int scale, int round)
      抽样标准差(空值不参与) 抽样标准差σ=sqrt(s^2),即标准差=方差的平方根
      参数:
      list - 集合
      scale - 小数位
      round - 舍入模式 参考BigDecimal静态常量 ROUND_UP = 0 舍入远离零的舍入模式 在丢弃非零部分之前始终增加数字(始终对非零舍弃部分前面的数字加 1) 如:2.36 转成 2.4
      ROUND_DOWN = 1 接近零的舍入模式 在丢弃某部分之前始终不增加数字(从不对舍弃部分前面的数字加1, 即截短). 如:2.36 转成 2.3
      ROUND_CEILING = 2 接近正无穷大的舍入模式 如果 BigDecimal 为正, 则舍入行为与 ROUND_UP 相同 如果为负, 则舍入行为与 ROUND_DOWN 相同 相当于是 ROUND_UP 和 ROUND_DOWN 的合集
      ROUND_FLOOR = 3 接近负无穷大的舍入模式 如果 BigDecimal 为正, 则舍入行为与 ROUND_DOWN 相同 如果为负, 则舍入行为与 ROUND_UP 相同 与ROUND_CEILING 正好相反
      ROUND_HALF_UP = 4 四舍五入
      ROUND_HALF_DOWN = 5 五舍六入
      ROUND_HALF_EVEN = 6 四舍六入 五留双(银行家舍入法)
      如果舍弃部分左边的数字为奇数, 则舍入行为与 ROUND_HALF_UP 相同(四舍五入)
      如果为偶数, 则舍入行为与 ROUND_HALF_DOWN 相同(五舍六入)
      如:1.15 转成 1.2, 因为5前面的1是奇数;1.25 转成 1.2, 因为5前面的2是偶数
      ROUND_UNNECESSARY=7 断言所请求的操作具有准确的结果,因此不需要舍入。如果在产生不精确结果的操作上指定了该舍入模式,则会抛出ArithmeticException异常
      返回:
      标准差
    • stdeva

      public static BigDecimal stdeva(List<BigDecimal> list, int scale, int round)
    • stdevp

      public static BigDecimal stdevp(List<BigDecimal> list, int scale, int round)
      总体标准差(空值不参与) 总体标准差σ=sqrt(s^2),即标准差=方差的平方根
      参数:
      list - 集合
      scale - 小数位
      round - 舍入模式 参考BigDecimal静态常量 ROUND_UP = 0 舍入远离零的舍入模式 在丢弃非零部分之前始终增加数字(始终对非零舍弃部分前面的数字加 1) 如:2.36 转成 2.4
      ROUND_DOWN = 1 接近零的舍入模式 在丢弃某部分之前始终不增加数字(从不对舍弃部分前面的数字加1, 即截短). 如:2.36 转成 2.3
      ROUND_CEILING = 2 接近正无穷大的舍入模式 如果 BigDecimal 为正, 则舍入行为与 ROUND_UP 相同 如果为负, 则舍入行为与 ROUND_DOWN 相同 相当于是 ROUND_UP 和 ROUND_DOWN 的合集
      ROUND_FLOOR = 3 接近负无穷大的舍入模式 如果 BigDecimal 为正, 则舍入行为与 ROUND_DOWN 相同 如果为负, 则舍入行为与 ROUND_UP 相同 与ROUND_CEILING 正好相反
      ROUND_HALF_UP = 4 四舍五入
      ROUND_HALF_DOWN = 5 五舍六入
      ROUND_HALF_EVEN = 6 四舍六入 五留双(银行家舍入法)
      如果舍弃部分左边的数字为奇数, 则舍入行为与 ROUND_HALF_UP 相同(四舍五入)
      如果为偶数, 则舍入行为与 ROUND_HALF_DOWN 相同(五舍六入)
      如:1.15 转成 1.2, 因为5前面的1是奇数;1.25 转成 1.2, 因为5前面的2是偶数
      ROUND_UNNECESSARY=7 断言所请求的操作具有准确的结果,因此不需要舍入。如果在产生不精确结果的操作上指定了该舍入模式,则会抛出ArithmeticException异常
      返回:
      标准差
    • stdevpa

      public static BigDecimal stdevpa(List<BigDecimal> list, int scale, int round)