Class MathUtil

java.lang.Object
org.seppiko.commons.utils.MathUtil

public class MathUtil extends Object
Math Util
Author:
Leonard Woo
  • Constructor Details

    • MathUtil

      public MathUtil()
  • Method Details

    • maxDecimal

      public static BigDecimal maxDecimal(List<BigDecimal> nums) throws NoSuchElementException
      BigDecimal list max number
      Parameters:
      nums - number list
      Returns:
      maximum
      Throws:
      NoSuchElementException - list is null
    • maxInteger

      public static BigInteger maxInteger(List<BigInteger> nums) throws NoSuchElementException
      BigInteger list max number
      Parameters:
      nums - number list
      Returns:
      maximum
      Throws:
      NoSuchElementException - list is null
    • minDecimal

      public static BigDecimal minDecimal(List<BigDecimal> nums) throws NoSuchElementException
      BigDecimal list min number
      Parameters:
      nums - number list
      Returns:
      minimum
      Throws:
      NoSuchElementException - list is null
    • minInteger

      public static BigInteger minInteger(List<BigInteger> nums) throws NoSuchElementException
      BigInteger list min number
      Parameters:
      nums - number list
      Returns:
      minimum
      Throws:
      NoSuchElementException - list is null
    • avgDecimal

      public static BigDecimal avgDecimal(List<BigDecimal> nums, RoundingMode roundingMode)
      BigDecimal list avg number
      Parameters:
      nums - number list
      roundingMode - RoundingMode
      Returns:
      average
    • avgDecimal

      public static double avgDecimal(List<BigDecimal> nums) throws NoSuchElementException
      BigDecimal list avg number
      Parameters:
      nums - number list
      Returns:
      average double
      Throws:
      NoSuchElementException - list is null
    • avgInteger

      public static BigDecimal avgInteger(List<BigInteger> nums, RoundingMode roundingMode)
      BigInteger list avg number
      Parameters:
      nums - number list
      roundingMode - RoundingMode
      Returns:
      average
    • format

      public static String format(String precisionPattern, double number)
      Double format
      Parameters:
      precisionPattern - precision pattern, e.g. 0.00
      number - double number
      Returns:
      formatted string
    • convertDecimalTo

      public static String convertDecimalTo(long num, char[] alphabet)
      Convert decimal to alphabet number
      Parameters:
      num - number (greater than 0)
      alphabet - alphabet
      Returns:
      alphabet base, if num lass than 1 will return null
    • convertToDecimal

      public static Long convertToDecimal(CharSequence num, char[] alphabet)
      Convert any base to decimal
      Parameters:
      num - number
      alphabet - base
      Returns:
      if return null than num parser failed